by rtkwe · 8y ago · 0 comments
The question is how much of an issue is this really? How often is 4 parts in 10 quadrillion a meaningful error when dealing with money? Especially when most of the time JS is dealing with money it will be presentation.
I spent 13 years maintaining a 2mloc reservation and accounting system that used floats for everything. By the time I got there and understood enough it was simply too late to do anything about it.
Just say no, really; that road leads to madness.
If you need precision; and many do; consider fixnums, rationals or bignums, in order of increasing complexity and flexibility.
This is in general how floating point math works.
The kind of issue do not want to have: issues with money that can go very wrong when calculating discounts, tax percentages, interest or whatever.
The firm I worked at used built in Java libraries and always deferred rounding until the very last possible moment.