MikeMcl / bignumber.js

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

multipliedBy work incorrect #299

Closed pripersian closed 3 years ago

pripersian commented 3 years ago

We have code

var MulNumber = BigNumber(4563579969884408065).multipliedBy(997).toFixed();
console.log(MulNumber);

We have result 4549889229974755075100

But in calculator or other library we have result = image 4549889229974754840805

Brucedayton commented 3 years ago

why you use toFixed()?

MikeMcl commented 3 years ago

@Brucedayton

toFIxed() is used to ensure that exponential notation is not used.

Conversely, toExponential() is used to ensure that exponential notation is used.

The mistake made above is that 4563579969884408065 should have been passed as a string, as it is too large for a JavaScript number.