Synthetic Industry

Troubleshooting guide · updated 2026-10-11

Django totals differ by a penny: trace decimal precision and rounding policy

Separate decimal storage, input conversion and line-versus-total rounding before applying a format-only fix to a business calculation.

Write the calculation rule first

Ask the finance owner whether each line is rounded before summing, which currency precision applies and how a half-unit is rounded. Two different policies can both produce internally consistent numbers. A bug requires a named expected result, not a preference for whichever displayed amount is smaller.

  • Use invented inputs that exercise fractional values, quantity multiplication and any permitted negative adjustment.
  • Separate display formatting from the amount stored and used by subsequent calculations.
  • Do not infer tax rules or currency precision from a generic two-decimal example.

Follow one value through every boundary

Django distinguishes DecimalField/Python Decimal from FloatField/Python float and specifies max_digits and decimal_places. Check input parsing, intermediate arithmetic, model precision, actual database backend and output formatting. A decimal model field cannot retroactively make every earlier floating-point calculation follow the owner's rounding policy.

  • Record types and exact synthetic values before and after each step.
  • Inspect whether a text input was first converted through a float.
  • Do not treat an SQLite-only test as proof of every production database's decimal behaviour.

Acceptance compares a declared result

An authored regression asserts the exact expected stored total and displayed amount for the same invented lines, including the agreed rounding edge. Capture the old-code assertion failure before editing. The neighbouring checks cover a whole-unit input and a maximum permitted value. These are proposed arithmetic checks, not audited invoices or executed results.

  • Formatting a wrong value to two decimals is not a repair.
  • Changing stored historical amounts or a column definition needs separate migration scope.

Non-fit and priced route

A single repeatable arithmetic defect with an owner-approved rule and synthetic fixtures may fit fix-one-bug-with-regression-test, from £295 after bounded reproduction and a fixed quote. Accounting policy, tax advice, currency conversion, schema/data migration and correction of real invoices do not fit this repair. If the rule is undecided, settle it with the finance owner before seeking a code fix.

  • No live charge, refund or invoice write is part of these checks.
  • Send the invented inputs and declared result, not financial records, code or credentials; prices are untested proposals.

Sources and limits