dandanyajin
今天更新博客了吗?

当数据超过 Number.MAX_SAFE_INTEGER (2 ^ 53 - 1) 时的计算都是不精确的

例如:

Math.pow(2, 53) === Math.pow(2, 53) + 1       // true

这个时候就可以使用 BigInt()

BigInt(Math.pow(2, 53)) === BigInt(Math.pow(2, 53)) + BigInt(1)      // false

 

 

 

使用 BigInt()需要注意的是:

BigInt  为系统数据类型;Number 为 数值型。不同类型是不能直接混用四则运算;相比较时可以使用“==”,不能使用“===”。

 

 

posted on 2022-07-26 11:38  dandanyajin  阅读(110)  评论(0编辑  收藏  举报