FAILURE MAP
← Case archive

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

The cash rounding adjustment is reported with the wrong sign · case 01

Rounding 2.02 down to 2.00 reports an adjustment of +0.02.

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

ROOT CAUSE

The adjustment is computed as exact - payable.

THE FAILURE

The adjustment is computed as exact - payable.

Unsuccessful approach: Reporting the absolute adjustment loses the direction of downward roundings.

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 = cash(exact)
    else:
        r = exact.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
    return [z(r, 2), z(exact - r, 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression adjustment-sign 1', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('regression adjustment-sign 2', (['2.025'], 'cash'), ['2.05', '0.025']),
  ('partial repair guard 2', (['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']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])],
 [('regression adjustment-sign 1', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('regression adjustment-sign 2', (['-1.03', '-0.99'], 'cash'), ['-2.00', '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: 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 adjustment-sign 1', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('regression adjustment-sign 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('partial repair guard 1', (['19.47', '26.34'], 'CASH'), ['45.80', '-0.010']),
  ('partial repair guard 2', (['17.98', '8.07', '0.335', '23.38'], 'Cash'), ['49.75', '-0.015']),
  ('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 adjustment-sign 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression adjustment-sign 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('partial repair guard 1', (['-1.435'], 'Cash'), ['-1.45', '-0.015']),
  ('partial repair guard 2', (['2.955'], ' cash '), ['2.95', '-0.005']),
  ('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 adjustment-sign 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('regression adjustment-sign 2', (['22.99', '2.02', '4.93', '0.185'], 'twint'), ['30.13', '0.005']),
  ('partial repair guard 1', (['1.91', '-3.315'], 'card'), ['-1.41', '-0.005']),
  ('partial repair guard 2', (['4.92'], ' cash '), ['4.90', '-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'])]]
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 adjustment-sign 1['2.00', '0.020']['2.00', '-0.020']Failed
regression adjustment-sign 2['2.05', '-0.025']['2.05', '0.025']Failed
partial repair guard 2['1.00', '0.020']['1.00', '-0.020']Failed
control: refund['-2.00', '-0.020']['-2.00', '0.020']Failed
control: refund to zero['0.00', '-0.020']['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 / 5c1cd1dd10a1a7cdea18fea4ea7bb0e884e60cad0a0d47b3b29e913aca327c45

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 = cash(exact)
    else:
        r = exact.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
    return [z(r, 2), z(abs(r - exact), 3)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression adjustment-sign 1', (['1.02', '1.00'], 'cash'), ['2.00', '-0.020']),
  ('regression adjustment-sign 2', (['2.025'], 'cash'), ['2.05', '0.025']),
  ('partial repair guard 2', (['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']),
  ('control: card exact', (['1.02'], 'card'), ['1.02', '0.000']),
  ('control: twint exact', (['3.33', '4.44'], 'twint'), ['7.77', '0.000'])],
 [('regression adjustment-sign 1', (['0.99', '0.03'], 'cash'), ['1.00', '-0.020']),
  ('regression adjustment-sign 2', (['-1.03', '-0.99'], 'cash'), ['-2.00', '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: 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 adjustment-sign 1', (['-0.02'], 'Cash '), ['0.00', '0.020']),
  ('regression adjustment-sign 2', (['3.00', '0.025'], 'cash'), ['3.05', '0.025']),
  ('partial repair guard 1', (['19.47', '26.34'], 'CASH'), ['45.80', '-0.010']),
  ('partial repair guard 2', (['17.98', '8.07', '0.335', '23.38'], 'Cash'), ['49.75', '-0.015']),
  ('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 adjustment-sign 1', (['-2.075'], 'cash'), ['-2.10', '-0.025']),
  ('regression adjustment-sign 2', (['12.40', '-3.12', '0.99'], ' CASH'), ['10.25', '-0.020']),
  ('partial repair guard 1', (['-1.435'], 'Cash'), ['-1.45', '-0.015']),
  ('partial repair guard 2', (['2.955'], ' cash '), ['2.95', '-0.005']),
  ('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 adjustment-sign 1', (['12.71', '-2.68'], 'Cash'), ['10.05', '0.020']),
  ('regression adjustment-sign 2', (['22.99', '2.02', '4.93', '0.185'], 'twint'), ['30.13', '0.005']),
  ('partial repair guard 1', (['1.91', '-3.315'], 'card'), ['-1.41', '-0.005']),
  ('partial repair guard 2', (['4.92'], ' cash '), ['4.90', '-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'])]]
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 adjustment-sign 1['2.00', '0.020']['2.00', '-0.020']Failed
regression adjustment-sign 2['2.05', '0.025']['2.05', '0.025']Passed
partial repair guard 2['1.00', '0.020']['1.00', '-0.020']Failed
control: refund['-2.00', '0.020']['-2.00', '0.020']Passed
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 / be080fa25754510c87820543d86ef5bf323da2a5d7b0e365cda6494f54b81d2d

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

Case digest / f24883f9b5c0340fa07e4684151805253a806a7b53af7b29466eed90797cc794