PHP floatval Function: Convert to Float Value

The floatval() function is used to retrieve the float value of a variable. It converts the variable to a floating point number and returns the converted result. If the variable cannot be converted to a floating point number, it returns 0.

$var = '10.5';
$floatVal = floatval($var);
echo $floatVal; // 输出 10.5

In the example above, the floatval() function is used to convert the string ‘10.5’ to a floating point number, which is then stored in the $floatVal variable. Finally, the output shows the result as 10.5.

bannerAds