How php casts a value to float
This article mainly introduces how php converts the value mandatory type to float, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Method: 1, in front of the variable enclosed in parentheses with the target type "(float)", syntax "(float) $val"; 2, with floatval (), syntax "floatval ($val)"; 3, with settype (), syntax "settype ($val," float ")".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php converts a value cast type to float
Method 1: add the target type "(float)" enclosed in parentheses before the variable to be converted
Method 2: use the floatval () function
Floatval (): used to get the floating-point value of a variable
Output result:
Method 3: use the settype () function
Syntax:
Settype ($var, $type)
The settype () function sets the variable $var to the specified $type type.
Example
Output result:
Description: the value that can be set for $type
"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)
The settype () function changes the type of the variable itself.
Thank you for reading this article carefully. I hope the article "how to convert the value mandatory type to float" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!