Repository navigation
Respect fraction_digits for unscaled compact numbers - #1486
Open
seragAhmed wants to merge 1 commit into
Open
seragAhmed wants to merge 1 commit into
seragAhmed wants to merge 1 commit into
Conversation
chrikrah
approved these changes
Nov 24, 2026
chrikrah
left a comment
Contributor
There was a problem hiding this comment.
This can be merged from my perspective: the #1484 repro at 931a39a matches ICU 78.3, carry cases included.
$ python repro.py # 931a39a, CLDR from scripts/download_import_cldr.py
12 # 12.345, en_US
1K # 999.6, en_US
$0 # 0.123 USD, en_US
1234 # 1234.5, de_DE
1万 # 9999.6, ja_JP
-1K # -999.6, en_US
$0.12 # 0.125 USD, fraction_digits=2 (half-even)
$ python -m pytest -q
7004 passed, 1218 skipped, 1 xfailed
# babel/numbers.py reverted to aeca9fa, tests kept:
FAILED tests/test_numbers.py::test_format_compact_currency
FAILED tests/test_numbers_format_decimal.py::test_compact_fraction_digits_unscaled
2 failed, 139 passed
$ ruff check . # ruff 0.14.10, the pre-commit pin
All checks passed!
Compact currency output changes for existing callers. Should CHANGES.rst say so?
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.
Fixes #1484.
_get_compact_format()now rounds tofraction_digitswhen formatting numbers below the smallest compact magnitude or matching a"0"compact pattern, instead of returning the unroundedDecimaldirectly. When rounding carries the value across a magnitude boundary (such as999.6to1000inen_US, or9999.6to10000inja_JP), it re-runs the lookup at the next magnitude so the compact suffix is selected from the rounded value.Verification
tests/test_numbers_format_decimal.pyandtests/test_numbers.pycoveringformat_compact_decimalandformat_compact_currencybelow the smallest magnitude, across magnitude carry boundaries, and on"0"patterns.pytest tests/test_numbers.py tests/test_numbers_format_decimal.py tests/test_support_format.py(159 passed) andruff check.