Home > Article > Backend Development > PHP floating point data types
In PHP, the float data type represents any number that contains a decimal part. The decimal part can contain digits after the decimal point, or it can be expressed in scientific notation using e or E. For example, 100 in scientific notation is 10e2.
The size of floating point numbers depends on the hardware/operating system platform, although it is common to find up to 14 digits of precision after the decimal point.
//Literal assignment of float value to variable $var=5327.496; // standard notation $var1=5.327496e3; // Scientific notation $var2=5.327496E3; //Scientific notation $var3=5_327.496; //sepration symbol
For better readability, integer literals can use "_" as delimiter, PHP scanner in This symbol will be ignored during processing.
$var=5_327.496; // it will treated as 5327.496
Since PHP 7.40 it is possible to use the delimiter symbol "_"
The following example shows the representation of floating point literals in standard notation.
Live Demonstration
<?php $var=5327.496; echo $var . ""; ?>
This will produce the following results -
5327.496
This example uses scientific notation
<?php $var1=5.327496e3; <br /> echo $var . "";<br />$var2=5.327496E3; <br /> echo $var . ""; ?>
This will produce the following results -
5327.496 5327.496
This example uses the delimiter "_" (this will run starting from PHP 7.40)
<?php $var3=5_327.496; echo $var . ""; ?>
This will produce the following results-
5327.496
The above is the detailed content of PHP floating point data types. For more information, please follow other related articles on the PHP Chinese website!