<?php
$int = 1968401665333658496;
echo json_encode( array("$int",$int) );
?>
Recieved in browser: [ "1968401665333658496" , 1968401665333658600 ]
It "rounds off" my integer?
Btw : PHP_INT_MAX = 9223372036854775807 ~ PHP Version 5.3.2-1ubuntu4.7
No problems with these huge integers anywhere (PHP, MySQL or Javascript)
- until json_encode(
) screws it up (silently btw..)
It's not just a JSON issue. If you put
alert(1968401665333658496);
in firebug console you get 1968401665333658600
You're probably hitting the JS max value.
There's a discussion on that here : What is JavaScript's highest integer value that a Number can go to without losing precision?
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 of 2^53
before any loss of precision.
I am not sure how you didn't have problems with numbers this large in JS alone - if you didn't your JS implementation is not standards compliant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With