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".

@b0rk I've heard "never use floating point for money in javascript". But that is hard because as soon as something is divided it is floating point. But we keep prices in pennies, never dollars.
@paulrosen even worse, even integers are floating point in Javascript although it's no big deal on numbers smaller than 9 quadrillion. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
Number.MAX_SAFE_INTEGER - JavaScript | MDN

The Number.MAX_SAFE_INTEGER static data property represents the maximum safe integer in JavaScript (253 – 1).

MDN Web Docs
@paulrosen @b0rk I hope that one day we have a fixed point number type in JS. It could be implemented using a BigInt for the value plus a number for where the decimal point should go, but BigInt has a bunch of limitations. Not being able to JSON encode it is a major one.
@paulrosen
@b0rk
Not true. Everything in JavaScript is a float. JS only has a single number type called Number (wasm excluded), which is a 64 bit float.

@paulrosen For integer division, can't always be sure that the result doesn't need rounding, so its somewhat hinting that you should use something that provides the right rounding method for the work you are doing (rounding up or down to a specific number, rounding certain transactions in certain directions, etc)

And then additionally needing to keep track of the decimal position too. It becomes complicated and deserving of a library of functions and wrappers.