News for hackers. Stuff that matters.
Re:Ask HN: How to handle financial calculations precisely? by wmf on Wednesday January 25, 2023 @02:58PM (#34523325)
The answer is never use floating point. Use BigDecimal for everything.
Re:Ask HN: How to handle financial calculations precisely? by fedeb95 on Wednesday January 25, 2023 @03:14PM (#34523540)
Sure thing. But how should I use BigDecimal optimally when performing operations between them? Which MathContext to set when dealing with money and specifically converting between amounts and percentages? I can't seem to find references online. Ideally I'd like some theorem that proves me I need a precision up to n for say amounts in the order of magnitude of ten billions.