Home>Article>Backend Development> What are the functions in php that convert values to floating point types?

What are the functions in php that convert values to floating point types?

青灯夜游
青灯夜游 Original
2022-06-13 15:33:12 2458browse

php has two functions to convert values to floating point types: 1. The floatval() function can obtain the floating point value of a variable. It is mainly used to convert variables to floating point types. The syntax "floatval() value)"; 2. The settype() function can set the variable to the specified type. When the second parameter is set to "float", the variable can be set to floating point type. The syntax is "settype($var,"float" )", this function will change the original variable, return TRUE if the setting is successful, and return FALSE if it fails.

What are the functions in php that convert values ​​to floating point types?

The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer

php transfers the value There are two functions for floating point types:

  • floatval()

  • settype()

1. Use floatval() to convert the value to floating point type

floatval() is used to obtain the floating point value of the variable, mainly used to convert the value Convert to floating point type.

What are the functions in php that convert values ​​to floating point types?

2. Use settype() to convert the value to floating point type

settype($var,$ type)function is used to set the variable $var to the specified type $type. Returns TRUE if the setting is successful and FALSE if it fails.

When the $type parameter of this function is set to "float", the value can be converted to floating point type.

Note: The settype() function will change the original variable.

What are the functions in php that convert values ​​to floating point types?

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the functions in php that convert values to floating point types?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What do php and jsp mean? Next article:What do php and jsp mean?