FAILURE MAP
← Case archive

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

The converted minor amount is truncated by int() · case 01

Converted amounts are systematically short by up to one minor unit, and negatives move toward zero.

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

ROOT CAUSE

int(v) truncates the exact product instead of rounding it.

THE FAILURE

int(v) truncates the exact product instead of rounding it.

Unsuccessful approach: Adding one half before truncating rounds positive ties up and mishandles every negative amount.

Case contract

solve(amount_minor, from_exp, to_exp, rate): amount_minor is an integer count of source minor units, rate a decimal string giving target major units per source major unit. The target minor amount is amount_minor * rate * 10**(to_exp - from_exp), computed exactly and rounded half-even to an integer.

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_minor, from_exp, to_exp, rate):
    scale = Decimal(10) ** (to_exp - from_exp)
    v = Decimal(amount_minor) * Decimal(rate) * scale
    return int(v)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression integer-rounding 1', (1000, 2, 0, '151.37'), 1514),
  ('regression integer-rounding 2', (-3, 2, 2, '0.5'), -2), ('partial repair guard 2', (-7, 2, 2, '0.3'), -2),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: zero', (0, 2, 0, '151.37'), 0)],
 [('regression integer-rounding 1', (123456, 2, 2, '1.08347'), 133761),
  ('regression integer-rounding 2', (987654321, 2, 3, '0.30712'), 3033283951),
  ('partial repair guard 1', (115, 2, 2, '1.1'), 126), ('partial repair guard 2', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
  ('control: zero', (0, 2, 0, '151.37'), 0), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514)],
 [('regression integer-rounding 1', (589334, 0, 0, '168.0593'), 99043060),
  ('regression integer-rounding 2', (64824, 0, 2, '51.9345'), 336660203),
  ('partial repair guard 1', (-66003, 3, 4, '7.30025'), -4818384),
  ('partial repair guard 2', (-35317, 0, 3, '196135.8'), -6926928048600),
  ('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
  ('control: large', (987654321, 2, 3, '0.30712'), 3033283951), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126)],
 [('regression integer-rounding 1', (410259, 2, 2, '0.258909'), 106220),
  ('regression integer-rounding 2', (286850, 2, 3, '1.495849'), 4290843),
  ('partial repair guard 1', (-46763, 3, 2, '4592.5'), -21475908),
  ('partial repair guard 2', (-35469, 3, 2, '139877.5'), -496131505),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2)],
 [('regression integer-rounding 1', (253357, 0, 4, '18.88901'), 47856629066),
  ('regression integer-rounding 2', (402529, 2, 4, '1.969810'), 79290565),
  ('partial repair guard 1', (-87559, 2, 2, '118188.8'), -10348493139),
  ('partial repair guard 2', (260569, 0, 4, '19.56965'), 50992441308), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
  ('control: zero', (0, 2, 0, '151.37'), 0), ('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
  ('control: large', (987654321, 2, 3, '0.30712'), 3033283951)]]
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 integer-rounding 115131514Failed
regression integer-rounding 2-1-2Failed
partial repair guard 2-2-2Passed
control: float trap tie126126Passed
control: negative exact-125-125Passed
control: yen to dinar307307Passed
control: zero00Passed

SHA-256 / 725a562826ded1ac3ffa0e842f4291b3ad19959ff65ff1913f3afa1d95d9acd1

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_minor, from_exp, to_exp, rate):
    scale = Decimal(10) ** (to_exp - from_exp)
    v = Decimal(amount_minor) * Decimal(rate) * scale
    return int(v + Decimal('0.5'))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression integer-rounding 1', (1000, 2, 0, '151.37'), 1514),
  ('regression integer-rounding 2', (-3, 2, 2, '0.5'), -2), ('partial repair guard 2', (-7, 2, 2, '0.3'), -2),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: zero', (0, 2, 0, '151.37'), 0)],
 [('regression integer-rounding 1', (123456, 2, 2, '1.08347'), 133761),
  ('regression integer-rounding 2', (987654321, 2, 3, '0.30712'), 3033283951),
  ('partial repair guard 1', (115, 2, 2, '1.1'), 126), ('partial repair guard 2', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
  ('control: zero', (0, 2, 0, '151.37'), 0), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514)],
 [('regression integer-rounding 1', (589334, 0, 0, '168.0593'), 99043060),
  ('regression integer-rounding 2', (64824, 0, 2, '51.9345'), 336660203),
  ('partial repair guard 1', (-66003, 3, 4, '7.30025'), -4818384),
  ('partial repair guard 2', (-35317, 0, 3, '196135.8'), -6926928048600),
  ('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
  ('control: large', (987654321, 2, 3, '0.30712'), 3033283951), ('control: cents to yen', (1000, 2, 0, '151.37'), 1514),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126)],
 [('regression integer-rounding 1', (410259, 2, 2, '0.258909'), 106220),
  ('regression integer-rounding 2', (286850, 2, 3, '1.495849'), 4290843),
  ('partial repair guard 1', (-46763, 3, 2, '4592.5'), -21475908),
  ('partial repair guard 2', (-35469, 3, 2, '139877.5'), -496131505),
  ('control: float trap tie', (115, 2, 2, '1.1'), 126), ('control: negative exact', (-250, 2, 2, '0.5'), -125),
  ('control: yen to dinar', (1, 0, 3, '0.3071'), 307), ('control: negative tie', (-3, 2, 2, '0.5'), -2)],
 [('regression integer-rounding 1', (253357, 0, 4, '18.88901'), 47856629066),
  ('regression integer-rounding 2', (402529, 2, 4, '1.969810'), 79290565),
  ('partial repair guard 1', (-87559, 2, 2, '118188.8'), -10348493139),
  ('partial repair guard 2', (260569, 0, 4, '19.56965'), 50992441308), ('control: negative tie', (-3, 2, 2, '0.5'), -2),
  ('control: zero', (0, 2, 0, '151.37'), 0), ('control: precise rate', (123456, 2, 2, '1.08347'), 133761),
  ('control: large', (987654321, 2, 3, '0.30712'), 3033283951)]]
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 integer-rounding 115141514Passed
regression integer-rounding 2-1-2Failed
partial repair guard 2-1-2Failed
control: float trap tie127126Failed
control: negative exact-124-125Failed
control: yen to dinar307307Passed
control: zero00Passed

SHA-256 / 56bd0c48637df1d27b0bfd28c41fdf43a48580d7112f659cc493045624ae118a

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

Case digest / 39c568c1b634c0c185868c9042a2a164aa3273ea77a5963277b959645902c170