警告:json_en code海量错误() [英] Warning: Massive error in json_encode()
问题描述
<?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.
这篇关于警告:json_en code海量错误()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!