Received in the browser: ...">

Warning: mass error in json_encode ()

<?php  
$int = 1968401665333658496;  
echo json_encode( array("$int",$int) );  
?>  

Received in the browser: [ "1968401665333658496" , 1968401665333658600 ]

Does it round my integer?

Btw: PHP_INT_MAX = 9223372036854775807 ~ PHP Version 5.3.2-1ubuntu4.7
No problem with these huge integers anywhere (PHP, MySQL or Javascript)
- until json_encode() screw it (silently btw ..)

+5
source share
3 answers

Javascript has no concept of integers; according to the standard, all numbers are IEEE doubles, which means they have 52 bits of mantissa. this leads to a practical maximum “integer” value 2^53before any loss of accuracy.

, , JS, - JS- .

+2

JSON.

alert(1968401665333658496);

firebug 1968401665333658600

, JS max.

: JavaScript, Number ?

+4

.

+1

All Articles