Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  94] [ 2]  / answers: 1 / hits: 83531  / 6 Years ago, sat, december 29, 2018, 12:00:00

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?


More From » bigint

 Answers
167

Turns out it's as easy as passing it to the Number constructor:


const myBigInt = BigInt(10);  // `10n` also works
const myNumber = Number(myBigInt);

Of course, you should bear in mind that your BigInt value must be within [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER] for the conversion to work properly, as stated in the question.


[#52854] Saturday, December 22, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cullenmaxl

Total Points: 414
Total Questions: 112
Total Answers: 87

Location: United States Minor Outlying Island
Member since Sat, May 28, 2022
2 Years ago
;