How php converts a string to a floating point
Many novices are not very clear about how php converts strings into floating-point types. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Php converts a string to a floating-point type: 1, add the target type "(float)", "(double)" or "(real)" enclosed in parentheses before the string variable, and the syntax "(float) $str"; 2, using the floatval () function, the syntax "floatval ($str)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Data type conversion refers to the conversion of variables or values from one data type to another. There are two methods of conversion, which are automatic type conversion and cast type conversion.
Let's take a look at two ways to convert a string to a floating-point type.
Add the target type (float), (double), (real) enclosed in parentheses before the variable
Use the floatval () function
Example 1:
Output result:
Example 2:
Output result:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.