23. February 2025
Avoiding death by accountant

If you work with financial data, you will run into the situation where you need to round calculated values to the nearest cent.
If you round up in every case, then that may work internally, but if your accounting package works otherwise (it will), and the other side of the ledger comes from somewhere other than your code, you may well have values that don’t balance exactly—which is critical for accounting purposes.
So it’s important to have these rounding algorithms in sync, or you’ll run into an angry accountant. Given the number of transactions that occur daily in most systems, this will pop up often if it doesn’t get done right.