openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.95k stars 528 forks source link

toFixed() float error with LOOOONG precision number #167

Open kennyklee opened 7 years ago

kennyklee commented 7 years ago

There is an issue with using native toFixed() function to apply precision for long decimals (e.g., greater than 15).

Expected: accounting.toFixed(1.005, 20); // "1.00499999999999989342"

Actual: accounting.toFixed(1.005, 20); // "1.00500000000000000000"

kennyklee commented 7 years ago

Likelihood of this bug being spotted in the wild is probably really low.