javascript - 翻译成另一个数字系统 JS

标签 javascript math numbers


我有一个字符串,我需要将这个字符串转换成另一个数字系统。
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. See Number.isSafeInteger() for more information.

MDN's notes on Number.MAX_SAFE_INTEGER

关于javascript - 翻译成另一个数字系统 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44071909/

相关文章:

c# - c#中,如何独立保证两台机器不会净生成相同的随机数?

javascript - 在 HTML 登陆页面中重新创建命令解释器的最佳方法?

javascript - Sanity.io,有什么方法可以轻松更改字段类型吗?

javascript - 导航到其他页面可以在 render() 调用中使用,但不能在单独的函数中使用

javascript - 如何使用 href 链接将 javascript 变量作为参数传递?

algorithm - 证明算法对于解决游戏是正确的

algorithm - 优化算术表达式序列的快速算法

c - 如何降低以下循环的时间复杂度?

math - 用于网络的简单数学库

c - 如何在 c 中存储 pow(10,n) 整数值,其中 n 可以 <200?