问题
I found myself in the situation where I wanted to convert a BigInt
value to a Number
value. Knowing that my value is a safe integer, how can I convert it?
回答1:
Turns out it's as easy as passing it to the Number
constructor:
const myBigInt = BigInt(10); // of course, `10n` also works
const myNumber = Number(myBigInt);
回答2:
You can use parseInt
or Number
const large = BigInt(309);
const b = parseInt(large);
console.log(b);
const n = Number(large);
console.log(n);
来源:https://stackoverflow.com/questions/53970655/how-to-convert-bigint-to-number-in-javascript