3 ms·
This is a fairly settled issue in finance AFAIK, but to the arguments. When doing math in finance, we need to be explicit about the precision we use, because w
by mhluongo 10y ago
This is a fairly settled issue in finance AFAIK, but to the arguments.
When doing math in finance, we need to be explicit about the precision we use, because we're counting finite things. Things like significant figures and rounding matter, and can't be ignored by imagining we have an "infinite precision" that throws away information, as floating point math does.
Using fixed-point decimal math as default helps mitigate this class of mistakes in this domain. It's similar to using a memory safe language outside embedded programming- if there's no value in the other option, and it's a source of bugs, eliminate it.
NB: Using fixed-point decimal math is similar to the advice to use integers, though it's a bit more flexible (eg keeping amounts in "BTC" with a fixed 8 decimal places instead of "satoshis").