MikeMcl / bignumber.js

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
http://mikemcl.github.io/bignumber.js
MIT License
6.63k stars 743 forks source link

Calculation of inexhaustible numbers is imprecise #321

Closed cinling closed 2 years ago

cinling commented 2 years ago

Calculation of inexhaustible numbers is imprecise

Expect:

let val
val = new BigNumber(1).dividedBy(1760)
val = val.multipliedBy(1760)
console.log(val)   // val = 1

Actual:

let val
val = new BigNumber(1).dividedBy(1760)
val = val.multipliedBy(1760)
console.log(val)   // val = 0.9999999999999999968 
MikeMcl commented 2 years ago

To see the value you are multiplying by 1760, try

val = new BigNumber(1).dividedBy(1760);
console.log(val.toString());

Then repeat it after entering say

BigNumber.set({ DECIMAL_PLACES: 40 });
cinling commented 2 years ago

这是来自QQ邮箱的假期自动回复邮件。   我也许不在,但我回尽快回复你的