Comment by grishka

1 year ago

While I've never worked on financial systems myself, I was told many times that monetary amounts should always be stored and manipulated as integer amounts of smallest units of currency (cents). One reason being that integer math is always exact, while floating-point isn't. And when money is involved, you want your math to be exact so everything always adds up every step of the way. So I'm always calling it out when someone is using floats to store money.

well, you could do this, but it would make world much more complex when working with the numbers in the code - todays highlevel languages like Java or C# have a "decimal" datatype which should be used for money/accounting, these types also offer several digits of accuracy, if required.