我在BigInt中进行了大量计算。如何将其转换为科学计数法?
var max = Number.MAX_SAFE_INTEGER;
console.log(max.toExponential(3).toString());
var big = BigInt(max.toString()+max.toString());
console.log(big.toExponential(3).toString())
可以将Intl.NumberFormat和{notation: 'scientific'}
一起使用
var max = Number.MAX_SAFE_INTEGER;
var big = BigInt(max.toString()+max.toString());
var formatter = new Intl.NumberFormat('en', {
notation: 'scientific'
});
console.log(formatter.format(big));
BigInt
和notation: scientific
两者在此回答日期之前都几乎不受浏览器的支持。如果您打算使用跨浏览器,请考虑checking their support。