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

How to convert string to floating point in php

王林
王林Original
2020-07-10 13:32:516523browse

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!

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