MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.45k stars 475 forks source link

Question about multiplication with large numbers that produces more zeroes #164

Closed amd-9 closed 3 years ago

amd-9 commented 3 years ago

Greetings!

I'm stuggling to figure out how multiplication works. Seems there can be a possible bug but I'm not sure.

For example const result = Decimal.mul('11111111111111111111111111', 10).toFixed() result will be 111111111111111111110000000 and for console.log(Decimal.mul('1111111111111111111', 10).toFixed()) result will be 11111111111111111110

Why in first example I'm getting additional zeroes in the end?

josdejong commented 3 years ago

I guess you have to configure a precision larger than the default of 20 digits

amd-9 commented 3 years ago

Thanks! It solved the issue

josdejong commented 3 years ago

👍