Home  >  Article  >  Backend Development  >  How to convert string to floating point number in php

How to convert string to floating point number in php

藏色散人
藏色散人Original
2020-07-10 09:22:477197browse

php method to convert floating point numbers: first save a string type decimal in the "$str" variable; then use float to force the string type to a floating point type; finally use "gettype() "The function can obtain the converted variable type.

How to convert string to floating point number in php

php Convert the string to floating point

Create a new php file, named test.php, Used to explain how PHP converts strings to floating point types.

How to convert string to floating point number in php

In the test.php file, use the header() method to set the encoding format of the page to utf-8 to avoid garbled characters when the page outputs Chinese.

How to convert string to floating point number in php

In the test.php file, save a string type decimal in the $str variable.

How to convert string to floating point number in php

In the test.php file, use float to cast the string type to a floating point type, and the result is saved in the $res variable.

How to convert string to floating point number in php

In the test.php file, use the gettype() function to obtain the converted variable type, and use echo to output the result.

How to convert string to floating point number in php

Open the test.php file in the browser to view the results.

How to convert string to floating point number in php

For more related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to convert string to floating point number in php. 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