我发现自己想将BigInt
值转换为Number
值。知道我的值是safe integer,该如何转换?
答案 0 :(得分:3)
结果证明,将其传递给Number
构造函数很容易:
const myBigInt = BigInt(10); // of course, `10n` also works
const myNumber = Number(myBigInt);
答案 1 :(得分:1)
您可以使用parseInt
或Number
const large = BigInt(309);
const b = parseInt(large);
console.log(b);
const n = Number(large);
console.log(n);