大整形运算
定義大整形
let n = 521n; console.log(n,typeof(n)); // 521n "bigint"整形轉換成大整形
let m = 123; console.log(BigInt(m)); //123n console.log(BigInt(1.2)); //報錯大數值運算
let max = Number.MAX_SAFE_INTEGER;console.log(max); //9007199254740991console.log(max + 1); //9007199254740992console.log(max + 2); //9007199254740992console.log(BigInt(max)) //9007199254740991nconsole.log(BigInt(max) + BigInt(1)) //9007199254740992nconsole.log(BigInt(max) + BigInt(2)) //9007199254740993n?如上圖所示,js支持的最大數值是9007199254740992,超度這個數字繼續運算,數值就不會再發生變化了,怎么解決這個問題呢?這里我們引入了大整形,這種類型的數據可以持續增加,沒有大小的束縛。
總結
- 上一篇: 买单吧如何激活信用卡(交通银行信用卡)
- 下一篇: 梦幻手游魔王怎么加点跟宝石