How to convert BigInt to Number in JavaScript?

Lucio Paiva picture Lucio Paiva · Dec 29, 2018 · Viewed 19.2k times · Source

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?

Answer

Lucio Paiva picture Lucio Paiva · Dec 29, 2018

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);