Rounded Out of a Refund — Python Bug Hunt
Inspired by the invoicing disputes born from Python's own round() — it's banker's rounding: round(2.5) is 2, round(3.5) is 4.
- Language: Python
- Layer: Backend
- Difficulty: Medium
- Concepts: Rounding, Money
- Modelled on: Python round()
- Visible tests: positive halves round up; non-halves round normally
- Reward: 50 XP for a complete fix
Briefing
Inspired by the invoicing disputes born from Python's own round() — it's banker's rounding: round(2.5) is 2, round(3.5) is 4. Finance signed off on classic half-up ("half away from zero"). The refunds engine uses the built-in.
rounding.py — implement true half-up.
Bug report
BUG-HALFUP · Priority: High · Reported by: billing disputes
half_up(x) — round half AWAY from zero:
- 2.5 -> 3, 3.5 -> 4, 2.4 -> 2
- -2.5 -> -3
Observed: round(2.5) == 2 shaved cents off exactly-half refunds; the ombudsman letter cites 40,000 affected invoices.
Logs
[refund] 2.5 -> 2 (customer expected 3)The code as shipped
src/fin/rounding.py (editable)
# Rounds to the nearest whole unit, halves away from zero.
def half_up(x):
return round(x)
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.