What is the standard solution in JavaScript for handling big numbers (BigNum)? [closed]

不羁岁月 提交于 2019-11-25 22:38:39

问题


Is there a bignum library for JavaScript or built-in that I can include like

<script type=\"text/javascript\" src=\"the_bignum_library.js\"></script>

?

I think my users would prefer to enter numbers in a web page and wait 7 seconds for a result, rather than download an executable and click through a bunch of \"this executable could possibly harm your computer\" warning screens to install it.

I\'ve considered basing my own off of http://github.com/silentmatt/javascript-biginteger or http://www.mainebrook.com/john/fun/euler.html. Or would you recommend calling from JavaScript into a Java bignum library such as apfloat?


回答1:


Update(2019-08-19): BigInt is now part of Firefox and Chrome; you no longer need a library:

const bigInt1 = 1111111111111111111111111111111n;
const bigInt2 = BigInt("1111111111111111111111111111111")
console.log((bigInt1 + bigInt2)+"")

Original answer:

If you need arbitrary-precision decimal numbers, use Javascript-bignum, as it is correct and fast.




回答2:


Big Number.



来源:https://stackoverflow.com/questions/3072307/what-is-the-standard-solution-in-javascript-for-handling-big-numbers-bignum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!