by SkiFire13 · 2mo ago · 0 comments
Note that the result of 0.1+0.2 does not lie in the interval containing 0.3, which is was confuses most people. The issue is that there is some imprecision in representing 0.1 and 0.2 too, and that compounds when summing, resulting in something that does not actually correspond to 0.3 (hence the classic 0.1+0.2!=0.3)
That makes me think that I can just plan ahead by storing the number of cents instead of dollars, or a “hack”, and then it makes me wonder why the format even requires me to do that.
That's what is generally suggested when handling money, at least for normal businesses (in finance related businesses you might have to handle a lot more decimal places for things like exchange rates, fractions of cryptos etc etc)
Be careful though that some currencies require more than 2 decimal places.