Introduction to integer types and floating point Numbers of PHP data types

  • 2020-06-01 08:37:17
  • OfStack

Syntax: integer values can be expressed in decimal, 106, or 8, preceded by an optional symbol (- or +). Base 8 means you must add 0 (zero) to a number, and base 106 means you must add 0x to a number.

$int1 = 100; / / decimal
$int2 = 123; / / negative
$int3 = 0123; / / 8 hexadecimal number
$int4 = 0 x1A; / / hexadecimal number 106

echo PHP_INT_SIZE; // shows that an integer is represented by a few bytes
echo " < br/ > ";
echo PHP_INT_MAX;echo " < br/ > "; // the largest number of integers (2147483647)
$fmax=2147483648;
var_dump (PHP_INT_MAX); The number of //1 is beyond integer and will be interpreted as float type.
echo " < br/ > ";
var_dump($fmax);

Floating point number: floating point number (double or real)
$a=1.34;
$b=1.8e308;
$c=8e-10;
var_dump($b);
// the word length of floating point Numbers is platform-dependent, although the maximum is usually 1.8e308 and has the precision of 14 decimal digits (no more than 14 digits)
// the precision should be calculated from the first non-zero number on the left.

For example: $a=567.9999899 // output 567.9999899

$b=789.8812345678543 // output 789.88123456785

$c=0.000000008907777777 // output 0.000000008907777777

Important to understand: precision is calculated from the first non-zero number on the left.


Related articles: