Javascript:toString(36) 用于大整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13573577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:11:14  来源:igfitidea点击:

Javascript: toString(36) for large integers

javascriptintegerlargenumberradix

提问by Meekohi

15955067621307336078.toString(36);returns '3d7vzfy5k2as8'in Javascript because the large integer cannot be represented (the correct answer is '3d7vzfy5k29ou').

15955067621307336078.toString(36);'3d7vzfy5k2as8'在 Javascript 中返回,因为无法表示大整数(正确答案是'3d7vzfy5k29ou')。

Does someone have a clever function that takes a large integer as a string and converts it to base 36?

有人有一个聪明的函数可以将一个大整数作为字符串并将其转换为基数 36 吗?

采纳答案by Robert Harvey

Use this BigInt class, which allows conversion of arbitrarily large integers to any arbitrary base between 2 and 95. Use the bigInt2str()method to perform the conversion.

使用这个 BigInt 类,它允许将任意大的整数转换为 2 到 95 之间的任意基数。使用该bigInt2str()方法执行转换。

回答by Meekohi

For anyone curious, today we are using https://github.com/MikeMcl/bignumber.jsinstead.

对于任何好奇的人,今天我们使用https://github.com/MikeMcl/bignumber.js代替。