以下是目前我尝试的方法。我的目标是得到一个12.34
:
BigInt('12340000000000000000') / BigInt('1000000000000000000')
12n
Number(BigInt('12340000000000000000') / BigInt('1000000000000000000'))
12
顺便提一下,当我使用JSBI库时,它可以按照我期望的方式工作:
JSBI.BigInt('12340000000000000000') / JSBI.BigInt('1000000000000000000');
12.34
这不可能本地实现吗?
Number(BigInt('x')) / Number(BigInt('y'))
怎么样?也就是说,两个本地数字的普通本地除法? - PointyBigInteger
相关的内容与BigDecimal
相关的内容不同。 - PointyNumber(BigInt('12340000000000000001'))
无法正常工作,因为使用 BigInt 的目的是保持完整的精度,如果只是将它转换成一个数字,就会丢失精度。结果将是12340000000000000000
。 - robmisiobut weird that the lib that is officially recommended as the fallback could do it
That's because your then just doingNumber / Number
,.. eg. You can do that calc without using JSBI.. In pure JS ->12340000000000000000 / 1000000000000000000 = 12.34
- KeithJSBI.divide('12340000000000000000', '1000000000000000000')
。 - Keith