Is there a decimal math library for JavaScript?

社会主义新天地 提交于 2019-11-26 06:44:49

问题


Is there a mature library for doing decimal-based math, possibly arbitrary-precision, in JavaScript?

Edit: I want this information for a reference page on floating-point-related problems and alternatives to use when binary floating-point is inappropriate: http://floating-point-gui.de/


回答1:


There's been a "port" of the Java BigDecimal class (I think it's here: http://freshmeat.net/projects/js_bigdecimal/ ) for a long time. I looked at it a long time ago and it seemed kind-of cumbersome and huge, but (if that's the one I'm thinking of) it's been used as part of some cryptography tools so there's a decent chance that it works OK.

Because cryptography is a likely area to generate a need for such things, that's a good way to snoop around for such packages.

edit: Thanks @Daniel (comment to question) for this older SO question: https://stackoverflow.com/questions/744099/javascript-bigdecimal-library




回答2:


As their author, I recommend bignumber.js or big.js, 'a small, fast Javascript library for arbitrary-precision arithmetic with decimal numbers'.

For a more mature library, the ICU4J BigDecimal translation is also recommended.




回答3:


Since it does not seem to be mentioned, here's another one. I haven't used it myself (yet), so I will update the post once I've given it a try.



来源:https://stackoverflow.com/questions/2622144/is-there-a-decimal-math-library-for-javascript

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