


PHP: Detailed explanation of floating point (float) data type examples
Apr 27, 2017 pm 05:04 PMWhat is the floating point (float) data type?
Floating point data types are our common decimals. Think "0.7" and "100.2", these are all floating point data. Floating point data types can be used to store both integers and decimals. . It has higher precision than the integer data type we talked about earlier.
The valid range of floating point type is 1.8E-308~1.8E+308.
Before PHP4.0, floating-point data was identified as double, also called double-precision floating-point number. There was no difference between the two.
There are two writing formats for floating-point data by default,A standard format, as follows
3.1415 -35.8
There is also a scientific notation format
3.14*10^3 可以使用3.14e3来表示
Float data type example
In the example below, we will test different numbers. PHP var_dump() will return the data type and value of the variable:
<?php $x = 10.3605; var_dump($x); echo "<br>"; $x = 2.4e3; var_dump($x); echo "<br>"; $x = 8E-5; var_dump($x); ?>
Code running result:
Floating point data is only an approximation value, so try to avoid comparisons between floating point values, because the final results are inaccurate. The result of running the code like the following
<?php $a=0.1; $b=0.7; if(($a+$b)==0.8){ echo "true"; }else{ echo 'false'; } ?>
:
We talked about the four scalar data types in PHP , boolean,string(string),integer(integer), plus the floating point type (float) in this chapter. In the next section, we will talk about "array (array)" among the two data types in PHP.
The above is the detailed content of PHP: Detailed explanation of floating point (float) data type examples. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the best data type for gender fields in MySQL?

What data type should be used for gender field in MySQL database?

Mind map of Python syntax: in-depth understanding of code structure

Python entry to proficiency: from zero basics to project development

Detailed explanation of how to use Boolean type in MySQL

What is the best data type choice for gender field in MySQL?
