Repository navigation
Conversation
`numberFmt()` and `numberCurrency()` pinned `minimumFractionDigits: 2` and `maximumFractionDigits: 2` for currency formatting. Those overrides win against the digit count that `Intl.NumberFormat` derives from the currency itself, so a zero-digit currency such as JPY formatted `¥5.55` instead of `¥6`, and a three-digit currency such as KWD was rounded down to `5.56`. Leaving both options unset restores each currency's own precision, and leaves two-digit currencies exactly as they were. Addresses messageformat#327
This branch has not been deployed
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.
Addresses #327 (the first of its two asks).
What's broken
numberFmt()inmf1/packages/runtime/src/fmt/number.tshard-codesminimumFractionDigits: 2/maximumFractionDigits: 2for the currency style, so every currency is formatted with two decimals regardless of what CLDR says for that code: JPY comes out as¥5.55instead of¥6, and KWD as5.56instead of5.555.Intl.NumberFormatalready applies the CLDR digit ranges itself; the pins are a remnant from before it did — as the maintainer noted on #327, "those lines could now be dropped" and PRs for that would be welcome.The fix
Drop the two pins in
numberFmt()(the{V, number, currency}/{V, number, currency:JPY}path) and do the same innumberCurrency()(the::currency/XXXskeleton path), lettingIntl.NumberFormatuse the CLDR digit range for the currency code:{V, number, currency}beforeja,JPY,V=5.55The total is ¥5.55.The total is ¥6.en,JPY,V=5.55(currency:JPY)The total is ¥5.55.The total is ¥6.en,KWD,V=5.555The total is 5.56.The total is 5.555.en,USD,V=5.555The total is 5.56.The total is 5.56.(unchanged)2-decimal currencies — the overwhelming majority, and every existing expectation in the repo — are unchanged, because CLDR's digit count for them is 2 anyway.
Scope
This is deliberately only the first half of #327, hence
Addressesrather thanFixes. The skeleton half of that issue (¤#,##0.0000should clamp to USD's 2 digits) lives in@messageformat/number-skeleton, is the disputed half, and needs its own change.Validation
Number formattertable inmf1/packages/core/src/messages.test.ts. Red first: on the pristine treeTests 4 failed | 188 passed (192); with the fix,192 passed.614f28f→Tests 2792 passed | 4 skipped; with the fix →2797 passed | 4 skipped— exactly the 5 new cases, and no existing expectation had to be edited.numberCurrencyfails exactly the 3 skeleton-currency cases; reverting onlynumberFmtfails exactly the{V, number, {type}}case. Neither hunk is carried by the other.npm test,npm run build,npm run lint,npx prettier --check ./5\.555\.$/because the currency symbol varies by ICU build; the digit counts themselves are ICU-version-independent.Prepared and tested with AI assistance; no human review is claimed.