today I'm thinking about the "don't use floating point for money" advice I hear all the time. It obviously has a lot of truth to it.

But -- Excel/Google Sheets uses floating point for all of its calculations, people use spreadsheets for money calculations all the time, and it generally seems to work just fine -- the results get rounded for display.

So I'm trying to figure out if there's a more nuanced guideline than "never use floating point for money".

thinking about trying to define a "safe zone" and a "danger zone" for floating point. maybe something like:

safe zone:
* all integer values (like 1.0, 234.0) behave 100% exactly the way you'd expect, UNLESS (!!!) they're more than 2^52. You can check for equality, it's fine.
* adding up ~100 numbers and rounding the result to 4 decimal places or so is going to work fine, as long as the numbers are roughly the same size

I think it's interesting to talk about floating point's "safe zone" (things you can do with floating point that are Completely 100% Fine Actually) because I think sometimes folks see that floating point is weird and kind of... overreact and treat it as a Magical Thing that could unexpectedly break at any time.
someone pointed out that this "never use floats for money" advice probably comes from the time of 32-bit floats, which have WAY less precision than 64-bit floats (8 digits instead of 16!) and are VERY VERY bad to use for money: you start losing 1 cent of accuracy around $100,000!!

@b0rk yes, but...when you're dealing with money, why would you ever choose to use something that has precision errors when you can choose a solution that doesn't?

It seems like good advice regardless of how many bits of precision we have. Equality tests going wonky 20 digits out vs 10 digits out is still a failing test.

@masukomi @b0rk It doesn't matter what data type you use, you can't represent 100/3 exactly (modulo symbolic algebra).

Everything has precision errors on a computer so I think it's a bit of a moot point. Sure, you can do better than floats with other data types at the cost of performance, but you can also use more sophisticated algorithms such as Kahan summation, also at the cost of performance.