gpt4 book ai didi

javascript - JSON 解析将某个数字转换为其他数字

转载 作者:行者123 更新时间:2023-11-29 15:24:41 24 4
gpt4 key购买 nike

<分区>

我发现一些数字在通过 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 不是,这背后的原因可能是什么?

我已经通过将所有内容解析为字符串解决了这个问题,但这是什么原因呢?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com