FA-61851 / Currency rounding and FX conversion / Open access
A negative amount that rounds to zero prints as minus zero · case 01
A refund of -0.004 USD is rendered as '-0.00'.
ROOT CAUSE
The quantized Decimal keeps its negative sign when the value rounds to zero.
THE FAILURE
The quantized Decimal keeps its negative sign when the value rounds to zero.
Unsuccessful approach: Replacing signed zero by Decimal(0) drops the sign but also discards the currency exponent, printing '0'.
Case contract
solve(amount, ccy): amount is an exact decimal string, ccy an ISO-like code that is trimmed and upper-cased. Minor-unit exponents: USD 2, EUR 2, JPY 0, KRW 0, KWD 3, BHD 3, CLF 4. Round the exact decimal half-even at the currency exponent and return a plain string with exactly that many fraction digits; a zero result is unsigned. Unknown codes return 'ERR:unknown-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
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(amount, ccy):
exps = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'BHD': 3, 'CLF': 4}
code = ccy.strip().upper()
if code not in exps: return 'ERR:unknown-currency'
e = exps[code]
x = Decimal(amount)
q = x.quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_EVEN)
q = q
return format(q, 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: cents tie to even', ('2.665', 'USD'), '2.66'), ('control: yen tie', ('1235.5', 'JPY'), '1236'),
('control: dinar three places', ('10.0005', 'KWD'), '10.000'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346'),
('control: lowercase code', ('12.345', ' eur '), '12.34'), ('control: integer input', ('7', 'BHD'), '7.000'),
('control: unknown code', ('1.00', 'ABC'), 'ERR:unknown-currency')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: integer input', ('7', 'BHD'), '7.000'), ('control: unknown code', ('1.00', 'ABC'), 'ERR:unknown-currency'),
('control: large amount', ('123456789.125', 'USD'), '123456789.12'),
('control: negative tie', ('-2.5', 'KRW'), '-2')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: negative tie', ('-2.5', 'KRW'), '-2'), ('control: cents tie to even', ('2.665', 'USD'), '2.66'),
('control: yen tie', ('1235.5', 'JPY'), '1236'), ('control: dinar three places', ('10.0005', 'KWD'), '10.000')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: dinar three places', ('10.0005', 'KWD'), '10.000'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346'),
('control: lowercase code', ('12.345', ' eur '), '12.34'), ('control: integer input', ('7', 'BHD'), '7.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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression signed-zero 1 | -0.00 | 0.00 | Failed |
| regression signed-zero 2 | -0 | 0 | Failed |
| control: cents tie to even | 2.66 | 2.66 | Passed |
| control: yen tie | 1236 | 1236 | Passed |
| control: dinar three places | 10.000 | 10.000 | Passed |
| control: unit of account four places | 1.2346 | 1.2346 | Passed |
SHA-256 / 9f33ab88d166498f2e228dadaf5b695e303d8ecad605a0539bdadaa93b7538b9
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(amount, ccy):
exps = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'BHD': 3, 'CLF': 4}
code = ccy.strip().upper()
if code not in exps: return 'ERR:unknown-currency'
e = exps[code]
x = Decimal(amount)
q = x.quantize(Decimal(1).scaleb(-e), rounding=ROUND_HALF_EVEN)
if q == 0 and q.is_signed(): q = Decimal(0)
return format(q, 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: cents tie to even', ('2.665', 'USD'), '2.66'), ('control: yen tie', ('1235.5', 'JPY'), '1236'),
('control: dinar three places', ('10.0005', 'KWD'), '10.000'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346'),
('control: lowercase code', ('12.345', ' eur '), '12.34'), ('control: integer input', ('7', 'BHD'), '7.000'),
('control: unknown code', ('1.00', 'ABC'), 'ERR:unknown-currency')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: integer input', ('7', 'BHD'), '7.000'), ('control: unknown code', ('1.00', 'ABC'), 'ERR:unknown-currency'),
('control: large amount', ('123456789.125', 'USD'), '123456789.12'),
('control: negative tie', ('-2.5', 'KRW'), '-2')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: negative tie', ('-2.5', 'KRW'), '-2'), ('control: cents tie to even', ('2.665', 'USD'), '2.66'),
('control: yen tie', ('1235.5', 'JPY'), '1236'), ('control: dinar three places', ('10.0005', 'KWD'), '10.000')],
[('regression signed-zero 1', ('-0.004', 'USD'), '0.00'), ('regression signed-zero 2', ('-0.4', 'JPY'), '0'),
('control: dinar three places', ('10.0005', 'KWD'), '10.000'),
('control: unit of account four places', ('1.23456', 'CLF'), '1.2346'),
('control: lowercase code', ('12.345', ' eur '), '12.34'), ('control: integer input', ('7', 'BHD'), '7.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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression signed-zero 1 | 0 | 0.00 | Failed |
| regression signed-zero 2 | 0 | 0 | Passed |
| control: cents tie to even | 2.66 | 2.66 | Passed |
| control: yen tie | 1236 | 1236 | Passed |
| control: dinar three places | 10.000 | 10.000 | Passed |
| control: unit of account four places | 1.2346 | 1.2346 | Passed |
SHA-256 / b8ffd63c30e8e844556a3badbac138166bd010113250e61eb50cf7f0b043a258
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 6 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:46:59.085140+00:00.
Case digest / 0b3079040ab0beff3697df2fe591508fae12df5c0b84a2a2a61224fa34992b0a