What is the maximum number of decimal places allowed in the float in PHP?

2

I was using Psysh to do tests with float numbers.

I noticed that after a certain amount, it begins to limit the decimal places.

Example:

 $float = 1.1234567891011121314

 echo $float; //  1.1234567891011

Why is this happening? Is there a maximum supported? If yes, what is the maximum supported?

If I need the full number, how do I get it?

    
asked by anonymous 23.06.2016 / 21:00

1 answer

5
  

Floating-point numbers have limited precision. Although it depends on the system, PHP generally uses the IEEE 754 dual-precision format, which will bring maximum precision due to rounds of the order of 1.11e-16. Uncommon math operations may cause major errors, and of course, error propagation must be considered when multiple operations are performed.

Source: link

  

The IEEE 754 standard (defined by the Institute of Electrical Engineers   and Electronics) was adopted in 1985 and has since undergone some   modifications, and defines some rules of normalization to be followed   operations and representations of binary numbers with   floating. Before that, each manufacturer of computers and other   devices, had a different representation format.

As for the accuracy of numerical representation, the main ones are:

Simple

32 bits or simple precision (float), equivalent to up to 7 decimal digits.

1 bit for the signal.

8 bits for the exponent.

23 bits for the representation of mantissa.

Double

64 bits or double precision, equivalent to up to 15 decimal digits.

1 bit intended for the signal;

11 bits destined for the exponent;

52 bits intended for mantissa.

Source: link

    
23.06.2016 / 21:05