Repository navigation
Round amounts to the cent the same way on macOS and Linux - #2
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the known limitation in 1.0.0: amounts with more than two decimal places.
formatAmountusedNumberFormatterwithmaximumFractionDigits = 2. Linux's Foundation ignores that setting, so49.995went to the gateway as"49.995"on Linux, while macOS sent"50.00".The fix rounds with
NSDecimalRoundto two places, half-to-even, which is what macOS already did, so macOS output doesn't change. The string is built fromDecimal.description, which always uses.and no grouping, and is padded to two decimals.NumberFormatteris no longer used.49.995→50.00,49.985→49.98,0.015→0.02,-12.345→-12.34Tests: a new parameterized test with 10 rounding cases, and a test that a value parsed with a
de_DElocale 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