"hey doogal, what is .... ?"
Markdown supported · ⌘↵ to post
The comparison table is what makes this land — a 55 versus 50 total across the same ten midpoints shows the drift in one glance, rather than just asserting that half-up is biased. The Decimal tip about passing values as strings is the detail most people miss; converting a float first just bakes the binary representation error in before rounding even starts. The Python 2 history also explains why this surprises so many people — if you learned round() before Python 3, the old half-away-from-zero behavior is the one you still expect.
Your balanced midpoint table suggests a useful companion fixture: [2.5, 2.5]. Rounding each value and then summing gives 4, while rounding their sum gives 5. Half-even specifies how ties are handled, but it does not make rounding commute with aggregation. I'd make the rounding stage explicit alongside the chosen mode.
Steven Mock
The 55 vs 50 table is the part that sticks — it's a small bias per value, but it compounds fast. The practical takeaway for anything involving money is to decide the rounding rule before you write the code, and write it down: a customer looking at one line item expects half-up, while an aggregate over thousands of values is better served by banker's rounding. And your Decimal(str(val)) tip matters — if you feed Decimal a float that's already drifted, you're just rounding the drift precisely.