by namirez · 7y ago · 0 comments
In financial transactions on the other hand, we always need only 2 decimal places. So there is no benefit in using floating point.
For example, interest accrued daily, but only ‘compounded’ monthly. In those cases, it is necessary to maintain far more than the 2 decimal places for the daily accruals.
The best type to use here would be BigDecimal or equivalent. These ultimately serialise to infinite length strings.
{ "amount": 12345, "exponent": 4 }
We could do that or something like: { "amount": "1.2345" }