警告:json_en code海量错误()海量、错误、json_en、code

由网友(名字被猫叼走了)分享简介::收到浏览器: [1968401665333658496,1968401665333658600] 据四舍五入我整?顺便说一句: PHP_INT_...
<?php  
$int = 1968401665333658496;  
echo json_encode( array("$int",$int) );  
?>  

:收到浏览器: [1968401665333658496,1968401665333658600]

据四舍五入我整?

顺便说一句: PHP_INT_MAX = 9223372036854775807〜PHP版本5.3.2-1ubuntu4.7 没有问题,这些巨大的整数的任何地方(PHP,MySQL或JavaScript)的 - 直到 json_en code()的螺丝它(默默顺便说一句..)

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..)

推荐答案

JavaScript有整数的概念,按照标准的所有数字是IEEE的双打,这意味着他们有52位尾数。这导致了实际的最大值整的数值 2 ^ 53 前的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.

我不知道你怎么没有问题,这个数字大JS孤独 - 如果你没有你的JS执行不符合标准

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.

阅读全文

相关推荐

最新文章