<分区>
我发现一些数字在通过 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
不是,这背后的原因可能是什么?
我已经通过将所有内容解析为字符串解决了这个问题,但这是什么原因呢?