如何在JavaScript中将BigInt转换为Number? [英] How to convert BigInt to Number in JavaScript?
本文介绍了如何在JavaScript中将BigInt转换为Number?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现自己想将一个 BigInt
值转换为一个 Number
值.知道我的值是一个安全整数,我怎么转换呢?
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?
推荐答案
结果就像将其传递给 Number
构造函数一样简单:
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);
这篇关于如何在JavaScript中将BigInt转换为Number?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文