Floats can't store most cent amounts exactly, so totals drift: 0.10 + 0.20 is 0.30000000000000004. For money, the decimal module stores the digits you write.
- Build a
Decimal from text: Decimal("0.10"). Decimal(0.1) copies the float's error into the Decimal.
- Add, subtract and multiply Decimals as usual; mixing with a float raises
TypeError, which catches mistakes early.
- Round to cents with
amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP). Python's round() rounds halves to the even number, so round(0.125, 2) is 0.12; invoices usually want 0.13.
Convert at the edges: read text into Decimal, do all the math, and turn the result into text for the report.