如何在Javascript中将科学符号转换为扩展字符串?
例如:如何在Javascript中将科学符号转换为扩展字符串?,javascript,bignum,Javascript,Bignum,例如: // Current behaviour 1e+25.toString() // Becomes "1e+25" // Want this instead 1e+25.toDecimalString() // Becomes "1000000000..." 您可以使用toLocalString()方法。试试这个: 1e+25.toLocaleString("en-US", { useGrouping: false }) /
// Current behaviour
1e+25.toString() // Becomes "1e+25"
// Want this instead
1e+25.toDecimalString() // Becomes "1000000000..."
您可以使用toLocalString()方法。试试这个:
1e+25.toLocaleString("en-US", { useGrouping: false })
// Output: "10000000000000000000000000"
1e+25
大于,不能准确表示为数字。您应该将其用于如此大的值。@axiac我不想表示为数字。仅将其转换为字符串-字符串没有限制。从什么转换?从一个数字,不是吗1e+25
是类型为Number
的值。这与1e+25+1
和接下来的10亿个整数值相等(由于JavaScript存储数字的方式)。如果您不使用BigInt
,您的方法从一开始就是无效的,您可能会在某个时候得到错误和意外的结果。