【发布时间】:2017-03-25 17:11:30
【问题描述】:
我发现在通过parseInt 时有一些号码正在更改为其他号码。
console.log( parseInt( 10153315281647662, 10 ) ); //10153315281647662
console.log( parseInt( 10153315281647663, 10 ) ); //10153315281647664
console.log( parseInt( 10153315281647664, 10 ) ); //10153315281647664
console.log( parseInt( 10153315281647665, 10 ) ); //10153315281647664
console.log( parseInt( 10153315281647666, 10 ) ); //10153315281647666
console.log( parseInt( 10153315281647667, 10 ) ); //10153315281647668
console.log( parseInt( 10153315281647668, 10 ) ); //10153315281647668
console.log( parseInt( 10153315281647669, 10 ) ); //10153315281647668
console.log( parseInt( 10153315281647660, 10 ) ); //10153315281647660
var str = '{ "id" : 10153315281647663 }';
console.log( JSON.parse( str ) ) // id : 10153315281647664
我正在处理一些大数字,parseInt 或将 str 更改为 JSON 与数字正在更改结果中的数字。这不是因为整数堆栈溢出,因为较大的数字 10153315281647666 解析正确,而 10153315281647663 解析不正确,这背后的原因是什么?
我已通过将所有内容解析为字符串来解决此问题,但这是什么原因?
【问题讨论】:
标签: javascript json