Get the App
SLTechnology News&Howtos  ›  Development  › 

How php converts a string to a floating point

Shulou Source: shulou.com Published: 2022-06-03 08:02:24 11月15日 Update

Many novices are not very clear about how php converts strings into floating-point types. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Php converts a string to a floating-point type: 1, add the target type "(float)", "(double)" or "(real)" enclosed in parentheses before the string variable, and the syntax "(float) $str"; 2, using the floatval () function, the syntax "floatval ($str)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Data type conversion refers to the conversion of variables or values from one data type to another. There are two methods of conversion, which are automatic type conversion and cast type conversion.

Let's take a look at two ways to convert a string to a floating-point type.

Add the target type (float), (double), (real) enclosed in parentheses before the variable

Use the floatval () function

Example 1:

Output result:

Example 2:

Output result:

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Type variable character string floating point data method function parenthesis target example result syntax use help enforcement output clear content for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Huawei Redmi Shulou Technology