Problem with PHP Integer

When I print this number in php 137582392964679 , I get this as output 1.37582392965E + 14

All I do is simple

print 137582392964679;

Does anyone know why he is doing this? It is as if it is automatically converted to an exponential number. Someone said this because I'm on a 32-bit machine. If so, how can I get around this?

thank

+3
source share
5 answers

Check const PHP_INT_MAX. You probably exceeded the maximum size, which is usually around 2 billion for a 32-bit system.

+2
source

, 32- , 2147483647. , , , .

, ?

, . GMP:

$sum = gmp_add("123456789012345", "76543210987655");
echo gmp_strval($sum) . "\n";

:

200000000000000

, , - BC Math.

- , , , .

+2

64- , . , : print number_format(137582392964679);

+1

, 32- , , . . , . , float printf. , 64-, , , , BC Math PHP.

+1

manual :

PHP , float.

Also, your number cannot be represented exactly because of the inherent limitations of floating point, therefore, it is approaching.

+1
source

Source: https://habr.com/ru/post/1781522/


All Articles