我有一个字符串,我需要将这个字符串转换成另一个数字系统。
1959113774617397110401052 - 以十进制表示法表示为三十进制(10 到 36)。
如果我尝试使用此代码:
var master = 1959113774617397110401052;
parseInt(master, 10).toString(36);
//8v0wc05bcz000000
它不能正常工作。
你能帮我知道我的错误在哪里以及如何正确使用它吗?
谢谢!
最佳答案
JavaScript 可以安全处理的最大整数是 9007199254740991
。这就是我们调用 Number.MAX_SAFE_INTEGER
时得到的结果。另一方面,您的数字要大得多:
9007199254740991
1959113774617397110401052
因此,JavaScript 无法使用此数字安全地执行数学计算,并且无法保证您会得到准确的结果。
The
MAX_SAFE_INTEGER
constant has a value of 9007199254740991. The reasoning behind that number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1.Safe in this context refers to the ability to represent integers exactly and to correctly compare them. For example,
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2
will evaluate to true, which is mathematically incorrect. SeeNumber.isSafeInteger()
for more information.
关于javascript - 翻译成另一个数字系统 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44071909/