You can convert a bigint to a number by simply using the Number
wrapper object like so:
// ES10+
const MAX_SAFE_INTEGER = 9007199254740991n;
console.log(Number(MAX_SAFE_INTEGER)); // 9007199254740991
Please be aware that the precision of a BigInt
value may be lost when it is coerced to a Number
value (and back).
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.