FA-62136 / Currency rounding and FX conversion / Open access
Negative minor amounts are split with floor division · case 01
-150 cents renders as '$-2.50'.
ROOT CAUSE
divmod on the signed amount floors the whole part and yields a positive remainder.
VERIFIED REPAIR
Split the absolute amount and apply the sign separately.
Unsuccessful approach: Truncating division fixes the magnitude but takes the sign from the whole part, losing it for amounts under one unit.
Case contract
solve(minor, ccy): format integer minor units. Styles: USD '$' prefix, ',' groups, '.' decimal, 2 digits; EUR ' €' suffix, '.' groups, ',' decimal, 2; JPY '¥' prefix, ',' groups, 0 digits (no decimal separator); CHF 'CHF ' prefix, "'" groups, '.', 2; KWD 'KD ' prefix, ',', '.', 3. Group the whole part in threes from the right; the fraction is zero-padded to the exponent. A negative amount places '-' before everything. Unknown codes return 'ERR:currency'.
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
N = 1
observations = []
def solve(minor, ccy):
spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
if ccy not in spec: return 'ERR:currency'
pre, suf, grp, dec, e = spec[ccy]
neg = minor < 0
major, frac = divmod(minor, 10 ** e)
digits = str(abs(major))
groups = []
while len(digits) > 3:
groups.insert(0, digits[-3:])
digits = digits[:-3]
groups.insert(0, digits)
body = grp.join(groups)
if e: body += dec + str(frac).zfill(e)
return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-divmod 1', (-150, 'USD'), '-$1.50'), ('regression negative-divmod 2', (-50, 'EUR'), '-0,50 €'),
('partial repair guard 2', (-50, 'KWD'), '-KD 0.050'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005')],
[('regression negative-divmod 1', (-50, 'KWD'), '-KD 0.050'),
('regression negative-divmod 2', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (-50, 'CHF'), '-CHF 0.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
[('regression negative-divmod 1', (-123456, 'EUR'), '-1.234,56 €'),
('regression negative-divmod 2', (-987654321, 'USD'), '-$9,876,543.21'),
('partial repair guard 1', (-5, 'CHF'), '-CHF 0.05'), ('partial repair guard 2', (-5, 'USD'), '-$0.05'),
('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
[('regression negative-divmod 1', (-99999, 'KWD'), '-KD 99.999'),
('regression negative-divmod 2', (-99999, 'USD'), '-$999.99'), ('partial repair guard 1', (-5, 'KWD'), '-KD 0.005'),
('partial repair guard 2', (-999, 'KWD'), '-KD 0.999'), ('control: small dollars', (105, 'USD'), '$1.05'),
('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: negative dollars', (-150, 'USD'), '-$1.50')],
[('regression negative-divmod 1', (-50, 'CHF'), '-CHF 0.50'),
('regression negative-divmod 2', (-105, 'EUR'), '-1,05 €'), ('partial repair guard 1', (-50, 'USD'), '-$0.50'),
('partial repair guard 2', (-5, 'EUR'), '-0,05 €'), ('control: negative dollars', (-150, 'USD'), '-$1.50'),
('control: negative euro cents', (-50, 'EUR'), '-0,50 €'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression negative-divmod 1 | -$2.50 | -$1.50 | Failed |
| regression negative-divmod 2 | -1,50 € | -0,50 € | Failed |
| partial repair guard 2 | -KD 1.950 | -KD 0.050 | Failed |
| control: dollars | $1,234.50 | $1,234.50 | Passed |
| control: yen | ¥1,234,567 | ¥1,234,567 | Passed |
| control: franc | CHF 123'456.78 | CHF 123'456.78 | Passed |
| control: dinar | KD 1.005 | KD 1.005 | Passed |
SHA-256 / 9ba5a6f818121399872685883dace094987df1acf77c4e16fb5a281f8ceec74f
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(minor, ccy):
spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
if ccy not in spec: return 'ERR:currency'
pre, suf, grp, dec, e = spec[ccy]
major, frac = int(minor / 10 ** e), abs(minor) % 10 ** e
neg = major < 0
digits = str(abs(major))
groups = []
while len(digits) > 3:
groups.insert(0, digits[-3:])
digits = digits[:-3]
groups.insert(0, digits)
body = grp.join(groups)
if e: body += dec + str(frac).zfill(e)
return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-divmod 1', (-150, 'USD'), '-$1.50'), ('regression negative-divmod 2', (-50, 'EUR'), '-0,50 €'),
('partial repair guard 2', (-50, 'KWD'), '-KD 0.050'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005')],
[('regression negative-divmod 1', (-50, 'KWD'), '-KD 0.050'),
('regression negative-divmod 2', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (-50, 'CHF'), '-CHF 0.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
[('regression negative-divmod 1', (-123456, 'EUR'), '-1.234,56 €'),
('regression negative-divmod 2', (-987654321, 'USD'), '-$9,876,543.21'),
('partial repair guard 1', (-5, 'CHF'), '-CHF 0.05'), ('partial repair guard 2', (-5, 'USD'), '-$0.05'),
('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
[('regression negative-divmod 1', (-99999, 'KWD'), '-KD 99.999'),
('regression negative-divmod 2', (-99999, 'USD'), '-$999.99'), ('partial repair guard 1', (-5, 'KWD'), '-KD 0.005'),
('partial repair guard 2', (-999, 'KWD'), '-KD 0.999'), ('control: small dollars', (105, 'USD'), '$1.05'),
('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: negative dollars', (-150, 'USD'), '-$1.50')],
[('regression negative-divmod 1', (-50, 'CHF'), '-CHF 0.50'),
('regression negative-divmod 2', (-105, 'EUR'), '-1,05 €'), ('partial repair guard 1', (-50, 'USD'), '-$0.50'),
('partial repair guard 2', (-5, 'EUR'), '-0,05 €'), ('control: negative dollars', (-150, 'USD'), '-$1.50'),
('control: negative euro cents', (-50, 'EUR'), '-0,50 €'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression negative-divmod 1 | -$1.50 | -$1.50 | Passed |
| regression negative-divmod 2 | 0,50 € | -0,50 € | Failed |
| partial repair guard 2 | KD 0.050 | -KD 0.050 | Failed |
| control: dollars | $1,234.50 | $1,234.50 | Passed |
| control: yen | ¥1,234,567 | ¥1,234,567 | Passed |
| control: franc | CHF 123'456.78 | CHF 123'456.78 | Passed |
| control: dinar | KD 1.005 | KD 1.005 | Passed |
SHA-256 / e29ff863a1c150f56fbb26a2e12368c13eeadb03818689efd629f74de02d73c3
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(minor, ccy):
spec = {'USD': ('$', '', ',', '.', 2), 'EUR': ('', ' €', '.', ',', 2), 'JPY': ('¥', '', ',', '.', 0), 'CHF': ('CHF ', '', "'", '.', 2), 'KWD': ('KD ', '', ',', '.', 3)}
if ccy not in spec: return 'ERR:currency'
pre, suf, grp, dec, e = spec[ccy]
neg = minor < 0
major, frac = divmod(abs(minor), 10 ** e)
digits = str(major)
groups = []
while len(digits) > 3:
groups.insert(0, digits[-3:])
digits = digits[:-3]
groups.insert(0, digits)
body = grp.join(groups)
if e: body += dec + str(frac).zfill(e)
return ('-' if neg else '') + pre + body + suf
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression negative-divmod 1', (-150, 'USD'), '-$1.50'), ('regression negative-divmod 2', (-50, 'EUR'), '-0,50 €'),
('partial repair guard 2', (-50, 'KWD'), '-KD 0.050'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005')],
[('regression negative-divmod 1', (-50, 'KWD'), '-KD 0.050'),
('regression negative-divmod 2', (-105, 'KWD'), '-KD 0.105'), ('partial repair guard 2', (-50, 'CHF'), '-CHF 0.50'),
('control: yen', (1234567, 'JPY'), '¥1,234,567'), ('control: franc', (12345678, 'CHF'), "CHF 123'456.78"),
('control: dinar', (1005, 'KWD'), 'KD 1.005'), ('control: unknown', (5, 'GBP'), 'ERR:currency')],
[('regression negative-divmod 1', (-123456, 'EUR'), '-1.234,56 €'),
('regression negative-divmod 2', (-987654321, 'USD'), '-$9,876,543.21'),
('partial repair guard 1', (-5, 'CHF'), '-CHF 0.05'), ('partial repair guard 2', (-5, 'USD'), '-$0.05'),
('control: unknown', (5, 'GBP'), 'ERR:currency'), ('control: million euros', (100000000, 'EUR'), '1.000.000,00 €'),
('control: zero yen', (0, 'JPY'), '¥0'), ('control: small dollars', (105, 'USD'), '$1.05')],
[('regression negative-divmod 1', (-99999, 'KWD'), '-KD 99.999'),
('regression negative-divmod 2', (-99999, 'USD'), '-$999.99'), ('partial repair guard 1', (-5, 'KWD'), '-KD 0.005'),
('partial repair guard 2', (-999, 'KWD'), '-KD 0.999'), ('control: small dollars', (105, 'USD'), '$1.05'),
('control: negative yen', (-1000, 'JPY'), '-¥1,000'), ('control: dollars', (123450, 'USD'), '$1,234.50'),
('control: negative dollars', (-150, 'USD'), '-$1.50')],
[('regression negative-divmod 1', (-50, 'CHF'), '-CHF 0.50'),
('regression negative-divmod 2', (-105, 'EUR'), '-1,05 €'), ('partial repair guard 1', (-50, 'USD'), '-$0.50'),
('partial repair guard 2', (-5, 'EUR'), '-0,05 €'), ('control: negative dollars', (-150, 'USD'), '-$1.50'),
('control: negative euro cents', (-50, 'EUR'), '-0,50 €'), ('control: yen', (1234567, 'JPY'), '¥1,234,567'),
('control: franc', (12345678, 'CHF'), "CHF 123'456.78")]]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression negative-divmod 1 | -$1.50 | -$1.50 | Passed |
| regression negative-divmod 2 | -0,50 € | -0,50 € | Passed |
| partial repair guard 2 | -KD 0.050 | -KD 0.050 | Passed |
| control: dollars | $1,234.50 | $1,234.50 | Passed |
| control: yen | ¥1,234,567 | ¥1,234,567 | Passed |
| control: franc | CHF 123'456.78 | CHF 123'456.78 | Passed |
| control: dinar | KD 1.005 | KD 1.005 | Passed |
SHA-256 / a51cbb174f08cfa32824a916e75511ce1401ae502336e5bcf2361411cca1f876
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:01.782433+00:00.
Case digest / 2a9ece40a7d7f517f81b218e7c8726d942a8bf923510172123df7879a89e2d86