How to convert string to floating point in php

王林
Release: 2023-03-02 10:02:01
Original
6486 people have browsed it

php method to convert a string to a floating point type is: it can be achieved through forced type conversion. We only need to add the target type enclosed in parentheses before the variable to be converted, such as [(float ), (double), (real)], indicating conversion to floating point type.

How to convert string to floating point in php

#You can convert a string to a floating point type by forcing the type.

(Recommended tutorial: php tutorial)

Type coercion in PHP is very similar to that in C: surround the variable to be converted with parentheses target type.

The allowed casts are:

  • (int), (integer) converted to integer

  • (bool), (boolean) are converted into Boolean type

  • (float), (double), (real) are converted into floating point type

  • (string)Convert to string

  • (array)Convert to array

  • (object)Convert to object

Code implementation:

How to convert string to floating point in php

Output result:

How to convert string to floating point in php

The above is the detailed content of How to convert string to floating point in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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