FAILURE MAP
← Case archive

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

A converted credit that rounds to zero is emitted as minus zero · case 01

A one-cent credit converted at 0.3 shows as '-0.00' on the invoice.

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

ROOT CAUSE

Rounded Decimal values keep a negative sign when they collapse to zero.

VERIFIED REPAIR

Normalize only zero results to their absolute value.

Unsuccessful approach: Taking the absolute value of every line erases the sign of genuine credits.

Case contract

solve(lines, rate, exp): lines are source-currency decimal strings (credits negative), rate a decimal string, exp the target exponent. The converted total is round_half_even(sum(lines)*rate) at exp. Each line is converted and rounded half-even individually; the difference between the converted total and the sum of converted lines is posted in full to the line with the largest absolute source amount (earliest on ties). Return the converted lines as plain strings; zero lines are unsigned. An empty invoice returns [].

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, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: (abs(src[k]), -k))
    conv[i] += diff
    return [format(c, 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 2', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('partial repair guard 2', (['2301.37', '-29.59', '-177.48'], '4.93100', 0), ['11348', '-146', '-875']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression signed-zero-line 1', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('regression signed-zero-line 2', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('partial repair guard 1', (['2091.78', '2339.22', '2608.61', '-64.15', '300.62'], '14.07556', 3),
   ['29442.975', '32925.831', '36717.647', '-902.947', '4231.395']),
  ('partial repair guard 2', (['1729.48', '-260.26', '1061.77', '2756.95'], '151.6104', 2),
   ['262207.15', '-39458.12', '160975.37', '417982.30']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00'])],
 [('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 1', (['607.45', '-205.45', '116.41', '195.72', '309.63'], '1991.467', 2),
   ['1209716.64', '-409146.90', '231826.67', '389769.92', '616617.93']),
  ('partial repair guard 2', (['-280.82', '2067.63', '2910.24', '2108.94'], '21.7286', 2),
   ['-6101.83', '44926.71', '63235.44', '45824.31']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-292.61', '2818.06', '1578.31', '1901.03', '2697.06'], '55.5721', 2),
   ['-16260.95', '156605.51', '87710.00', '105644.23', '149881.29']),
  ('partial repair guard 2', (['1616.46', '-55.89', '2559.69'], '35.6985', 3), ['57705.197', '-1995.189', '91377.094']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 signed-zero-line 1['30.00', '-0.00']['30.00', '0.00']Failed
regression signed-zero-line 2['-54.22', '21.70', '-0.00']['-54.22', '21.70', '0.00']Failed
partial repair guard 2['-5.00', '5.00']['-5.00', '5.00']Passed
control: three equal lines['5.02', '5.00', '5.00']['5.02', '5.00', '5.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed
control: dinar target['0.384', '0.768']['0.384', '0.768']Passed

SHA-256 / 681c6313cd2067a82756a715c3162a2d20e3da6f5e629ddcee67e22184faaffc

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, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: (abs(src[k]), -k))
    conv[i] += diff
    return [format(abs(c), 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 2', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('partial repair guard 2', (['2301.37', '-29.59', '-177.48'], '4.93100', 0), ['11348', '-146', '-875']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression signed-zero-line 1', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('regression signed-zero-line 2', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('partial repair guard 1', (['2091.78', '2339.22', '2608.61', '-64.15', '300.62'], '14.07556', 3),
   ['29442.975', '32925.831', '36717.647', '-902.947', '4231.395']),
  ('partial repair guard 2', (['1729.48', '-260.26', '1061.77', '2756.95'], '151.6104', 2),
   ['262207.15', '-39458.12', '160975.37', '417982.30']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00'])],
 [('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 1', (['607.45', '-205.45', '116.41', '195.72', '309.63'], '1991.467', 2),
   ['1209716.64', '-409146.90', '231826.67', '389769.92', '616617.93']),
  ('partial repair guard 2', (['-280.82', '2067.63', '2910.24', '2108.94'], '21.7286', 2),
   ['-6101.83', '44926.71', '63235.44', '45824.31']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-292.61', '2818.06', '1578.31', '1901.03', '2697.06'], '55.5721', 2),
   ['-16260.95', '156605.51', '87710.00', '105644.23', '149881.29']),
  ('partial repair guard 2', (['1616.46', '-55.89', '2559.69'], '35.6985', 3), ['57705.197', '-1995.189', '91377.094']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 signed-zero-line 1['30.00', '0.00']['30.00', '0.00']Passed
regression signed-zero-line 2['54.22', '21.70', '0.00']['-54.22', '21.70', '0.00']Failed
partial repair guard 2['5.00', '5.00']['-5.00', '5.00']Failed
control: three equal lines['5.02', '5.00', '5.00']['5.02', '5.00', '5.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed
control: dinar target['0.384', '0.768']['0.384', '0.768']Passed

SHA-256 / 33ce7943eba02998057a1b73a3004cffcfa6fc66f84bf56b91fa200686a2660e

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, rate, exp):
    r = Decimal(rate)
    qt = Decimal(1).scaleb(-exp)
    def q(v): return v.quantize(qt, rounding=ROUND_HALF_EVEN)
    src = [Decimal(l) for l in lines]
    if not src: return []
    conv = [q(v * r) for v in src]
    total = q(sum(src, Decimal(0)) * r)
    diff = total - sum(conv, Decimal(0))
    i = max(range(len(conv)), key=lambda k: (abs(src[k]), -k))
    conv[i] += diff
    return [format(abs(c) if c == 0 else c, 'f') for c in conv]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 2', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('partial repair guard 2', (['2301.37', '-29.59', '-177.48'], '4.93100', 0), ['11348', '-146', '-875']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76'])],
 [('regression signed-zero-line 1', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('regression signed-zero-line 2', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('partial repair guard 1', (['2091.78', '2339.22', '2608.61', '-64.15', '300.62'], '14.07556', 3),
   ['29442.975', '32925.831', '36717.647', '-902.947', '4231.395']),
  ('partial repair guard 2', (['1729.48', '-260.26', '1061.77', '2756.95'], '151.6104', 2),
   ['262207.15', '-39458.12', '160975.37', '417982.30']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70']),
  ('control: three equal lines', (['10.01', '10.01', '10.01'], '0.5', 2), ['5.02', '5.00', '5.00']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00'])],
 [('regression signed-zero-line 1', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('regression signed-zero-line 2', (['-50.05', '20.03', '-0.004'], '1.0833', 2), ['-54.22', '21.70', '0.00']),
  ('partial repair guard 1', (['607.45', '-205.45', '116.41', '195.72', '309.63'], '1991.467', 2),
   ['1209716.64', '-409146.90', '231826.67', '389769.92', '616617.93']),
  ('partial repair guard 2', (['-280.82', '2067.63', '2910.24', '2108.94'], '21.7286', 2),
   ['-6101.83', '44926.71', '63235.44', '45824.31']),
  ('control: credit and debit', (['-3.33', '3.33'], '1.5', 2), ['-5.00', '5.00']),
  ('control: empty invoice', ([], '1.1', 2), []),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768'])],
 [('regression signed-zero-line 1', (['459.88', '678.92', '1035.66', '1782.23', '-0.03'], '8.49695', 0),
   ['3908', '5769', '8800', '15143', '0']),
  ('regression signed-zero-line 2', (['100.00', '-0.01'], '0.3', 2), ['30.00', '0.00']),
  ('partial repair guard 1', (['-292.61', '2818.06', '1578.31', '1901.03', '2697.06'], '55.5721', 2),
   ['-16260.95', '156605.51', '87710.00', '105644.23', '149881.29']),
  ('partial repair guard 2', (['1616.46', '-55.89', '2559.69'], '35.6985', 3), ['57705.197', '-1995.189', '91377.094']),
  ('control: yen target', (['19.99', '5.01', '0.99'], '151.37', 0), ['3026', '758', '150']),
  ('control: dinar target', (['1.25', '2.50'], '0.3071', 3), ['0.384', '0.768']),
  ('control: single line', (['123.45'], '0.9215', 2), ['113.76']),
  ('control: largest is credit', (['-50.05', '20.03', '20.03'], '1.0833', 2), ['-54.22', '21.70', '21.70'])]]
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 signed-zero-line 1['30.00', '0.00']['30.00', '0.00']Passed
regression signed-zero-line 2['-54.22', '21.70', '0.00']['-54.22', '21.70', '0.00']Passed
partial repair guard 2['-5.00', '5.00']['-5.00', '5.00']Passed
control: three equal lines['5.02', '5.00', '5.00']['5.02', '5.00', '5.00']Passed
control: empty invoice[][]Passed
control: yen target['3026', '758', '150']['3026', '758', '150']Passed
control: dinar target['0.384', '0.768']['0.384', '0.768']Passed

SHA-256 / 8f7c1c87aa39eb5ffd095a4235d2fa795da868c87d46de55de3a7fbebaab487a

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

Case digest / 2518ac23d8f52daf46d1fb9920fc0c78366cd865ecd2b8685dc4d00c436bd8ea