php method to convert a string to a floating point type is: it can be achieved through forced type conversion. We only need to add the target type enclosed in parentheses before the variable to be converted, such as [(float ), (double), (real)], indicating conversion to floating point type.
#You can convert a string to a floating point type by forcing the type.
(Recommended tutorial: php tutorial)
Type coercion in PHP is very similar to that in C: surround the variable to be converted with parentheses target type.
The allowed casts are:
(int), (integer) converted to integer
(bool), (boolean) are converted into Boolean type
(float), (double), (real) are converted into floating point type
(string)Convert to string
(array)Convert to array
(object)Convert to object
Code implementation:
Output result:
The above is the detailed content of How to convert string to floating point in php. For more information, please follow other related articles on the PHP Chinese website!