Skip to content

Round amounts to the cent the same way on macOS and Linux - #2

Merged
taplin merged 1 commit into
mainfrom
amount-rounding
Oct 29, 2026
Merged

taplin merged 1 commit into
mainfrom
amount-rounding

Conversation

@taplin

@taplin taplin commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Fixes the known limitation in 1.0.0: amounts with more than two decimal places.

formatAmount used NumberFormatter with maximumFractionDigits = 2. Linux's Foundation ignores that setting, so 49.995 went to the gateway as "49.995" on Linux, while macOS sent "50.00".

The fix rounds with NSDecimalRound to two places, half-to-even, which is what macOS already did, so macOS output doesn't change. The string is built from Decimal.description, which always uses . and no grouping, and is padded to two decimals. NumberFormatter is no longer used.

  • 49.995 → 50.00, 49.985 → 49.98, 0.015 → 0.02, -12.345 → -12.34
  • The README's Operations section now says how amounts are sent and rounded.

Tests: a new parameterized test with 10 rounding cases, and a test that a value parsed with a de_DE locale is still sent with .. All 16 tests pass on macOS and on Linux with Swift 6.2 and 6.4, built with warnings as errors. Against the old code, 9 of the 10 rounding cases fail on Linux 6.2.

Intended as 1.0.1.

🤖 Generated with Claude Code

formatAmount used NumberFormatter, whose maximumFractionDigits is ignored
on Linux, so 49.995 went to the gateway as "49.995" there while macOS
sent "50.00". Round with NSDecimalRound (half-to-even, matching what
macOS already did) and build the string from Decimal.description, so
the output no longer depends on Foundation's formatter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@taplin
taplin merged commit fb52c26 into main Oct 29, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant