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

How to convert string to floating point number in php

藏色散人
Release: 2023-03-02 08:42:01
Original
7286 people have browsed it

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template