FAILURE MAP
← Case archive

FA-62006 / Currency rounding and FX conversion / Open access

Cash rounding is applied to each line instead of the basket total · case 01

A basket of 1.02 and 1.02 is charged 2.00 instead of 2.05.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Each line is rounded to 0.05 and the rounded lines are summed.

THE FAILURE

Each line is rounded to 0.05 and the rounded lines are summed.

Unsuccessful approach: Quantizing the total with Decimal('0.05') only fixes the exponent and performs no 5-rappen rounding.

Case contract

solve(lines, tender): lines are CHF decimal strings with up to three decimals (weight- or volume-priced items; refund lines negative). The exact total is their sum. For tender 'cash' (compared after trimming and lower-casing) the total is rounded to the nearest 0.05 with ties away from zero; every other tender ('card', 'twint', 'voucher', ...) pays the total rounded half-up to 0.01. Return [payable as a 2-decimal string, adjustment as a 3-decimal string] where adjustment = payable - exact; zeros are unsigned.

Why this case matters

Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(lines, tender):
    def cash(v):
        return (v / Decimal('0.05')).quantize(Decimal(1), rounding=ROUND_HALF_UP) * Decimal('0.05')
    def z(d, e):
        d = d.quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_UP)
        return format(abs(d) if d == 0 else d, 'f')
    exact = sum((Decimal(l) for l in lines), Decimal('0.000'))
    if tender.strip().lower() == 'cash':
        r = sum((cash(Decimal(l)) for l in lines), Decimal('0.00'))
    else:
        r = exact.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
    return [z(r, 2), z(r - exact, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression rounding-scope 1', (['1.02', '1.02'], 'cash'), ['2.05', '0.010']),
  ('regression rounding-scope 2', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('partial repair guard 2', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])],
 [('regression rounding-scope 1', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('regression rounding-scope 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('partial repair guard 1', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000']),
  ('control: positive tie', (['3.00', '0.025'], 'cash'), ['3.05', '0.025'])],
 [('regression rounding-scope 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('regression rounding-scope 2', (['17.98', '8.07', '0.335', '23.38'], 'Cash'), ['49.75', '-0.015']),
  ('partial repair guard 1', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('partial repair guard 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('control: negative tie', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('control: voucher exact', (['7.07'], 'voucher'), ['7.07', '0.000']),
  ('control: mixed basket', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('control: round down', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020'])],
 [('regression rounding-scope 1', (['7.95', '16.09', '-3.325', '23.21'], 'cash'), ['43.95', '0.025']),
  ('regression rounding-scope 2', (['12.08', '3.43', '4.44', '-4.37'], ' cash '), ['15.60', '0.020']),
  ('partial repair guard 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('partial repair guard 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('control: round down', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('control: round to franc', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020'])],
 [('regression rounding-scope 1', (['22.60', '28.56', '15.17'], ' cash '), ['66.35', '0.020']),
  ('regression rounding-scope 2', (['1.095', '2.025', '14.13'], 'cash'), ['17.25', '0.000']),
  ('partial repair guard 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('partial repair guard 2', (['19.47', '26.34'], 'CASH'), ['45.80', '-0.010']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression rounding-scope 1['2.00', '-0.040']['2.05', '0.010']Failed
regression rounding-scope 2['1.05', '0.030']['1.00', '-0.020']Failed
partial repair guard 2['2.00', '-0.020']['2.00', '-0.020']Passed
control: refund['-2.05', '-0.030']['-2.00', '0.020']Failed
control: refund to zero['0.00', '0.020']['0.00', '0.020']Passed
control: card exact['1.02', '0.000']['1.02', '0.000']Passed
control: twint exact['7.77', '0.000']['7.77', '0.000']Passed

SHA-256 / f747a20b42583c2237f95debf1d17b0eb221ae055b2dc2a2081921b786587811

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(lines, tender):
    def cash(v):
        return (v / Decimal('0.05')).quantize(Decimal(1), rounding=ROUND_HALF_UP) * Decimal('0.05')
    def z(d, e):
        d = d.quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_UP)
        return format(abs(d) if d == 0 else d, 'f')
    exact = sum((Decimal(l) for l in lines), Decimal('0.000'))
    if tender.strip().lower() == 'cash':
        r = exact.quantize(Decimal('0.05'), rounding=ROUND_HALF_UP)
    else:
        r = exact.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
    return [z(r, 2), z(r - exact, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression rounding-scope 1', (['1.02', '1.02'], 'cash'), ['2.05', '0.010']),
  ('regression rounding-scope 2', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('partial repair guard 2', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])],
 [('regression rounding-scope 1', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('regression rounding-scope 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('partial repair guard 1', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000']),
  ('control: positive tie', (['3.00', '0.025'], 'cash'), ['3.05', '0.025'])],
 [('regression rounding-scope 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('regression rounding-scope 2', (['17.98', '8.07', '0.335', '23.38'], 'Cash'), ['49.75', '-0.015']),
  ('partial repair guard 1', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('partial repair guard 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('control: negative tie', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('control: voucher exact', (['7.07'], 'voucher'), ['7.07', '0.000']),
  ('control: mixed basket', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('control: round down', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020'])],
 [('regression rounding-scope 1', (['7.95', '16.09', '-3.325', '23.21'], 'cash'), ['43.95', '0.025']),
  ('regression rounding-scope 2', (['12.08', '3.43', '4.44', '-4.37'], ' cash '), ['15.60', '0.020']),
  ('partial repair guard 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('partial repair guard 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('control: round down', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('control: round to franc', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020'])],
 [('regression rounding-scope 1', (['22.60', '28.56', '15.17'], ' cash '), ['66.35', '0.020']),
  ('regression rounding-scope 2', (['1.095', '2.025', '14.13'], 'cash'), ['17.25', '0.000']),
  ('partial repair guard 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('partial repair guard 2', (['19.47', '26.34'], 'CASH'), ['45.80', '-0.010']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020']),
  ('control: refund to zero', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression rounding-scope 1['2.04', '0.000']['2.05', '0.010']Failed
regression rounding-scope 2['1.02', '0.000']['1.00', '-0.020']Failed
partial repair guard 2['2.02', '0.000']['2.00', '-0.020']Failed
control: refund['-2.02', '0.000']['-2.00', '0.020']Failed
control: refund to zero['-0.02', '0.000']['0.00', '0.020']Failed
control: card exact['1.02', '0.000']['1.02', '0.000']Passed
control: twint exact['7.77', '0.000']['7.77', '0.000']Passed

SHA-256 / 30cffacfa32e46e00ad20ba99d4db8cb300e1d25ff63c7b0767b57e2a3c11ad5

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:47:00.700005+00:00.

Case digest / 97da1f3a56c577563fb9b21c3a7b45e240c6d75bd44dfa0bdf45cf246eaca012