Money arithmetic audit: floating-point, rounding and allocation errors in billing code

by fidji DeepSeek English ~702 tokens
Public excerpt Locked
Inventory of every money operation, the numeric type used, then worked counter-examples to the cent: 0.1 + 0.2, a 100.00 split three ways, tax rounded per line versus per invoice. Fix with integer minor units or decimals and a largest-remainder allocation…

About this prompt

Audits code that handles prices, taxes, discounts, currency conversion and payment splits for the cent-level errors that create accounting gaps: binary floating point, rounding per line versus per total, lost cents when splitting, double rounding. DeepSeek computes every case digit by digit and shows the discrepancy, so finance and developers can verify each finding by hand.

Example output

Provided by the author
STEP 3 — COUNTER-EXAMPLES 1. Float sum (line 8): 0.1 + 0.2 = 0.30000000000000004 → `total === 0.3` is false; the "paid in full" check fails. 2. Rounding helper (line 14): Math.round(1.005 * 100) / 100. 1.005 * 100 = 100.49999999999999 → rounds to 100 → 1.00 instead of 1.01. Error: 0.01. 3. Split (line 31): 100.00 / 3 = 33.333… → rounded 33.33 × 3 = 99.99. Missing: 0.01 per split. Largest remainder: 10,000 cents / 3 = 3,333 rem 1 → parts 3,334 + 3,333 + 3,333 = 10,000 ✓ → 33.34, 33.33, 33.33. 4. Tax per line vs per invoice (20%, three lines at 0.99): Per line: 0.99 × 0.20 = 0.198 → 0.20; × 3 = 0.60 Per invoice: 2.97 × 0.20 = 0.594 → 0.59 Difference 0.01. Your rule says "per invoice": line 22 must change. STEP 4 — FIX Store amounts as integer cents; one helper roundHalfUp(cents, scale)…

Details

Model
DeepSeek
Prompt language
English
Who it's for
Developers of invoicing, checkout, payroll or marketplace payout systems
Length
~702 tokens (estimate)
Delivered as
Prompt text, shown online after purchase

Reviews

Buyers only

No reviews yet. Only buyers of this prompt can leave one.

Report this prompt