Closed chend25 closed 7 months ago
const result = BigNumber(3.15) .times(BigNumber(1).div(3)); const res1 = result.toFixed(); // '1.0499999999999999999895' const res2 = result.toNumber(); // 1.05 const res3 = result.toFixed(1); // '1.0' const res4 = BigNumber(res1).toFixed(1); // '1.0' const res5 = BigNumber(res2).toFixed(1); // '1.1'
When res1 and res2 above are rounded to one decimal place, the results are different. By manual calculation, we know that 1.05 is the correct result I would expect res1 and res2 to have the same result when rounded to one decimal place
I would expect res1 and res2 to have the same result when rounded to one decimal place
Why?
I don't see anything unexpected. Notice that BigNumber(1).div(3) is not the same as a third.
BigNumber(1).div(3)
When res1 and res2 above are rounded to one decimal place, the results are different. By manual calculation, we know that 1.05 is the correct result I would expect res1 and res2 to have the same result when rounded to one decimal place