JS中大数的乘除运算如何得到精确的整数结果?
假设我们有:
var a = 75643564363473453456342378564387956906736546456235342;
var b = 34986098309687982743378379458582778387652482;
将这些数字相乘得到一个采用科学“e”表示法的数字。如何显示整个精确整数结果数?
我尝试过使用这个库 https://github.com/peterolson/BigInteger.js
自述文件说:
Note that Javascript numbers larger than 9007199254740992 and smaller than -9007199254740992 are not precisely represented numbers and will not produce exact results. If you are dealing with numbers outside that range, it is better to pass in strings.
但是如何用字符串进行数学运算呢?
最佳答案
使用bigInt,正如您所暗示的,您需要使用字符串而不是数字来正确表示它们。
bigInt("75643564363473453456342378564387956906736546456235342").multiply("34986098309687982743378379458582778387652482");
关于javascript - JS中大数算术运算如何得到精确的整数结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45352173/