JavaScript中+运算符的行为来存储大量数字?
要在JavaScript中存储大量数字,请使用BigInt()而不是+运算符。如果将使用+运算符,则可能会损失精度。
假设以下是我们的大量存储,我们使用BigInt()-
console.log("Loss of precision with + operator..")示例
以下是代码-
var stringValue1="100";
console.log("The integer value=");
console.log(+stringValue1);
var stringValue2="2312123211345545367";
console.log("Loss of precision with + operator..")
console.log(+stringValue2);
const storeLongInteger=BigInt("2312123211345545367");
console.log("No loss of precision with BigInt()");
console.log(storeLongInteger);要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo212.js。
输出结果
在控制台上的输出如下-
PS C:\Users\Amit\JavaScript-code> node demo213.js The integer value= 100 Loss of precision with + operator.. 2312123211345545000 No loss of precision with BigInt()2312123211345545367n
热门推荐
10 娘家除夕祝福语大全简短
11 对上司的简短祝福语
12 生日祝福语简短激励女生
13 生日哥哥祝福语简短独特
14 鼓励孩子小考祝福语简短
15 敏字的祝福语简短
16 新人结婚简短祝福语大全
17 升学祝福语简短的个性
18 甄嬛传祝福语简短