How php converts float to string
This article mainly introduces php how to convert float into a string, the article is very detailed, has a certain reference value, interested friends must read it!
Php converts float into a string: 1, add the target type "(string)" enclosed in parentheses before the float variable to be converted; 2, use the "strval ($float)" statement; 3, use the "settype ($float," string ")" statement.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Method 1: add the target type enclosed in parentheses (string) before the float variable to be converted
Output result:
Method 2: use the strval () function
The strval () function can get the string value of a variable
Output result:
Method 3: use the settype () function
The settype ($var, $type) function is used to set or convert the type of variable, converting $var to $type.
The possible values for type are:
"boolean" (or "bool", starting with PHP 4.2.0)
"integer" (or "int", starting with PHP 4.2.0)
"float" (available only after PHP 4.2.0, "double" used in older versions is now disabled)
"string"
"array"
"object"
"null" (since PHP 4.2.0)
Example:
Output result:
Note: settype () modifies the type of the variable itself, returns true if the setting is successful, and false if it fails.
The above is all the content of the article "how php converts float to string". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!