MikeMcl/bignumber.js

Calculation of inexhaustible numbers is imprecise

Closed this issue · 2 comments

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 

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 });