$rootbeer = (float) $InvoicedUnits;
Should do it for you. Check out Type-Juggling. You should also read String conversion to Numbers.
Answer from Sampson on Stack Overflow Top answer 1 of 8
272
$rootbeer = (float) $InvoicedUnits;
Should do it for you. Check out Type-Juggling. You should also read String conversion to Numbers.
2 of 8
100
You want the non-locale-aware floatval function:
float floatval ( mixed $var ) - Gets the float value of a string.
Example:
$string = '122.34343The';
$float = floatval($string);
echo $float; // 122.34343
PHP
php.net › manual › en › function.floatval.php
PHP: floatval - Manual
For the sake of comparing and to make myself clear I use the name parseFloat in stead of getFloat for the new function: <?php function parseFloat($ptString) { if (strlen($ptString) == 0) { return false; } $pString = str_replace(" ", "", $ptString); if (substr_count($pString, ",") > 1) $pString = str_replace(",", "", $pString); if (substr_count($pString, ".") > 1) $pString = str_replace(".", "", $pString); $pregResult = array(); $commaset = strpos($pString,','); if ($commaset === false) {$commaset = -1;} $pointset = strpos($pString,'.'); if ($pointset === false) {$pointset = -1;} $pregResultA =
W3Schools
w3schools.com › php › func_var_floatval.asp
PHP floatval() Function
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
The parseFloat() method parses a value as a string and returns the first number.
Easymorph
help.easymorph.com › doku.php
ParseFloat(text) [EasyMorph Help]
ParseFloat(text) syntax:functions:parsefloat · ParseFloat(text) Description · Arguments · Remarks · Examples · See also · Category: Text function · This function parses a number in scientific notation (as a text value) into a decimal number. Return value type: Number ·
Locutus
locutus.io › php › var › floatval
PHP's floatval in JavaScript | Locutus
February 2, 2026 - The native parseFloat() method of JavaScript returns NaN when it encounters a string before an int or float value. Here's what our current JavaScript equivalent to PHP's floatval looks like.
Reddit
reddit.com › r/learnprogramming › php: can´t convert string to float
r/learnprogramming on Reddit: PHP: Can´t convert string to float
November 25, 2021 -
EDIT: SOLVED.
Simplified example:
$A = "41"; $B = floatval($A);
B returns 0. Was kind of expecting 41, but it doesnt. What am i doing wrong?$A gets data from a function, but when i echo it out, it writes 41. Adding floatval, changes it to 0.
Real code:
/*TEsting output*/ echo "Supprice:" . $suppPrice; echo "<br />Floatvalg supprice: ". floatval($suppPrice);
**Output:**Supprice:41Floatvalg supprice: 0
EDIT: Adding info.
w3resource
w3resource.com › php › function-reference › floatval.php
PHP floatval() function - w3resource
?php $var_name1="122.00,50"; $var_name2="122.00"; $var_name3="122.50"; $var_name4="122,50"; $var_name5="122 50"; $var_name6="0.50"; $var_name7="0,50"; $var_name8="-122.50"; $var_name9="-122,50"; $var_name10="-122 50"; echo floatval($var_name1)."<br>"; echo floatval($var_name2)."<br>"; echo floatval($var_name3)."<br>"; echo floatval($var_name4)."<br>"; echo floatval($var_name5)."<br>"; echo floatval($var_name6)."<br>"; echo floatval($var_name7)."<br>"; echo floatval($var_name8)."<br>"; echo floatval($var_name9)."<br>"; echo floatval($var_name10)."<br>"; ?>
Functions-Online
functions-online.com › floatval.html
test floatval online - general PHP functions - functions-online
Test and run floatval online in your browser. Gets the float value of $var.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript | MDN
The parseFloat function converts its first argument to a string, parses that string as a decimal number literal, then returns a number or NaN.