FAILURE MAP
← Case archive

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

A 5-rappen tie on a cash refund rounds toward positive infinity · case 01

A cash refund of -2.075 pays out -2.05 while a 2.075 sale charges 2.10.

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

ROOT CAUSE

Rounding adds one half and floors, which is not symmetric for negative totals.

VERIFIED REPAIR

Round ties away from zero for both sales and refunds.

Unsuccessful approach: Switching to half-even rounding breaks ties toward even multiples instead of away from zero.

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') + Decimal('0.5')).quantize(Decimal(1), rounding=ROUND_FLOOR) * 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 = cash(exact)
    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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['7.95', '16.09', '-3.325', '23.21'], 'cash'), ['43.95', '0.025']),
  ('partial repair guard 2', (['-0.46', '-0.885', '26.47'], 'CASH'), ['25.15', '0.025']),
  ('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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['1.825'], 'CASH'), ['1.85', '0.025']),
  ('partial repair guard 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('control: positive tie', (['3.00', '0.025'], 'cash'), ['3.05', '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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['22.51', '1.915'], 'Cash'), ['24.45', '0.025']),
  ('partial repair guard 2', (['8.51', '22.58', '28.67', '0.565'], 'Cash'), ['60.35', '0.025']),
  ('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']),
  ('control: round to franc', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020'])],
 [('regression refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['3.51', '-0.375', '11.09'], 'Cash'), ['14.25', '0.025']),
  ('partial repair guard 2', (['15.83', '18.48', '1.715'], 'Cash'), ['36.05', '0.025']),
  ('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 refund-tie-direction 1['-2.05', '0.025']['-2.10', '-0.025']Failed
regression refund-tie-direction 2['-1.00', '0.025']['-1.05', '-0.025']Failed
partial repair guard 2['3.05', '0.025']['3.05', '0.025']Passed
control: round down['2.00', '-0.020']['2.00', '-0.020']Passed
control: round to franc['1.00', '-0.020']['1.00', '-0.020']Passed
control: refund['-2.00', '0.020']['-2.00', '0.020']Passed
control: refund to zero['0.00', '0.020']['0.00', '0.020']Passed

SHA-256 / 56a58067d5a87d090fd7ebd999f2e9fbff70cda9e77b89189ec52e5dd4bbdb98

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_EVEN) * 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 = cash(exact)
    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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['7.95', '16.09', '-3.325', '23.21'], 'cash'), ['43.95', '0.025']),
  ('partial repair guard 2', (['-0.46', '-0.885', '26.47'], 'CASH'), ['25.15', '0.025']),
  ('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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['1.825'], 'CASH'), ['1.85', '0.025']),
  ('partial repair guard 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('control: positive tie', (['3.00', '0.025'], 'cash'), ['3.05', '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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['22.51', '1.915'], 'Cash'), ['24.45', '0.025']),
  ('partial repair guard 2', (['8.51', '22.58', '28.67', '0.565'], 'Cash'), ['60.35', '0.025']),
  ('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']),
  ('control: round to franc', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020'])],
 [('regression refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['3.51', '-0.375', '11.09'], 'Cash'), ['14.25', '0.025']),
  ('partial repair guard 2', (['15.83', '18.48', '1.715'], 'Cash'), ['36.05', '0.025']),
  ('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 refund-tie-direction 1['-2.10', '-0.025']['-2.10', '-0.025']Passed
regression refund-tie-direction 2['-1.00', '0.025']['-1.05', '-0.025']Failed
partial repair guard 2['3.00', '-0.025']['3.05', '0.025']Failed
control: round down['2.00', '-0.020']['2.00', '-0.020']Passed
control: round to franc['1.00', '-0.020']['1.00', '-0.020']Passed
control: refund['-2.00', '0.020']['-2.00', '0.020']Passed
control: refund to zero['0.00', '0.020']['0.00', '0.020']Passed

SHA-256 / 3d18bda14f37d1b37ec527de78fb58b0f38fb15568af58f46c5f518bc882c1aa

3 / The verified repair

Exit 0
"""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 = cash(exact)
    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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['7.95', '16.09', '-3.325', '23.21'], 'cash'), ['43.95', '0.025']),
  ('partial repair guard 2', (['-0.46', '-0.885', '26.47'], 'CASH'), ['25.15', '0.025']),
  ('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 refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['1.825'], 'CASH'), ['1.85', '0.025']),
  ('partial repair guard 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('control: positive tie', (['3.00', '0.025'], 'cash'), ['3.05', '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 refund-tie-direction 1', (['-0.075'], 'cash'), ['-0.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-0.625'], 'cash'), ['-0.65', '-0.025']),
  ('partial repair guard 1', (['22.51', '1.915'], 'Cash'), ['24.45', '0.025']),
  ('partial repair guard 2', (['8.51', '22.58', '28.67', '0.565'], 'Cash'), ['60.35', '0.025']),
  ('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']),
  ('control: round to franc', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('control: refund', (['-1.03', '-0.99'], 'cash'), ['-2.00', '0.020'])],
 [('regression refund-tie-direction 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression refund-tie-direction 2', (['-1.025'], 'cash'), ['-1.05', '-0.025']),
  ('partial repair guard 1', (['3.51', '-0.375', '11.09'], 'Cash'), ['14.25', '0.025']),
  ('partial repair guard 2', (['15.83', '18.48', '1.715'], 'Cash'), ['36.05', '0.025']),
  ('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 refund-tie-direction 1['-2.10', '-0.025']['-2.10', '-0.025']Passed
regression refund-tie-direction 2['-1.05', '-0.025']['-1.05', '-0.025']Passed
partial repair guard 2['3.05', '0.025']['3.05', '0.025']Passed
control: round down['2.00', '-0.020']['2.00', '-0.020']Passed
control: round to franc['1.00', '-0.020']['1.00', '-0.020']Passed
control: refund['-2.00', '0.020']['-2.00', '0.020']Passed
control: refund to zero['0.00', '0.020']['0.00', '0.020']Passed

SHA-256 / b62b35ddd422334e28b3e8ef6add6536bbd45e280d3257161cf1a830820fef6f

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.699446+00:00.

Case digest / 7fcbb56d04f1acc058034d7f32b7a9fbb5d179cb11edeb5da96eef658f72d6f3