php method to convert floating point numbers: first save a string type decimal in the "$str" variable; then use float to force the string type to a floating point type; finally use "gettype() "The function can obtain the converted variable type.
php Convert the string to floating point
Create a new php file, named test.php, Used to explain how PHP converts strings to floating point types.
In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid garbled characters when the page outputs Chinese.
In the test.php file, save a string type decimal in the $str variable.
In the test.php file, use float to cast the string type to a floating point type, and the result is saved in the $res variable.
In the test.php file, use the gettype() function to obtain the converted variable type, and use echo to output the result.
Open the test.php file in the browser to view the results.
For more related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to convert string to floating point number in php. For more information, please follow other related articles on the PHP Chinese website!