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.96k stars 530 forks source link

accounting.toFixed(1.005, 2) is 1.00 #169

Open zbobyuan opened 7 years ago

zbobyuan commented 7 years ago

the expected result is 1.01.

gustavlrsn commented 7 years ago

I think this is a case of the minified file not being updated yet. You can use the regular file in the meanwhile until it's updated.

@wjcrowcroft I could fix this in my open PR if you'd like, if so, can I use any minifier?

zbobyuan commented 7 years ago

great, thx!

madmacc commented 3 years ago

This is still an issue. I would expect 1.005 to be 1.01 not 1.00.

madmacc commented 3 years ago

The latest version in npm 0.41 has this issue but I copied the code from github (0.42) and it fixes it however it is still not working as expected. accounting.toFixed(1.0049, 2) is 1.00 I would expect this to be 1.01 the same as 1.005 above.

overthemike commented 3 years ago

@madmacc Just out of curiosity, why do you expect 1.0049 to be 1.01? Are you rounding all number from right to left? My default expectation would be to drop anything after the 3rd decimal and only round based on what's left.

madmacc commented 3 years ago

@overthemike Yes I would expect all numbers to round from right to left. Why choose the 3rd decimal are you assuming it is a currency you are dealing with? What if you want the answer to 5 decimal places and you currently have it to 10 places?