MikeMcl / decimal.js

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

add function don't work in 10.4.0 version. #206

Closed FrancescBagur closed 2 years ago

FrancescBagur commented 2 years ago

I'm using the add function as in the next example:

new Decimal('10.25').add(new Decimal('2.3')).toNumber()

and it returns "13". There are no decimals in the result.

MikeMcl commented 2 years ago

That would only happen if the precision has been set to 2.

Decimal.precision = 2;
new Decimal('10.25').add('2.3').toNumber();
// 13

At the default precision the answer is of course as expected:

Decimal.precision = 20;
new Decimal('10.25').add('2.3').toNumber();
// 12.55

Anything else?

FrancescBagur commented 2 years ago

Thank you very much. This was the problem ;)