Skip to content

Apply exponent grouping for scientific notation patterns - #1281

Open
lin-hongkuan wants to merge 2 commits into
python-babel:masterfrom
lin-hongkuan:codex/scientific-exponent-grouping
Open

lin-hongkuan wants to merge 2 commits into
python-babel:masterfrom
lin-hongkuan:codex/scientific-exponent-grouping

Conversation

@lin-hongkuan

Copy link
Copy Markdown

Fixes #1026.

LDML scientific notation treats the maximum number of integer digits in a scientific pattern as the exponent grouping size. Babel only shifted by the minimum integer digit count, so patterns such as ##0.####E0 formatted 12345 as 1.2345E4 instead of 12.345E3.

This changes the scientific notation normalization to use the maximum integer digit count when it is larger than the minimum, while preserving the existing fixed-minimum behavior for patterns without exponent grouping.

Checks run locally:

  • python setup.py import_cldr
  • python -m pytest tests\test_numbers.py tests\test_numbers_format_decimal.py -q (140 passed)
  • python -m pre_commit run --files babel\numbers.py tests\test_numbers.py tests\test_numbers_format_decimal.py --show-diff-on-failure --color=never
  • PYTHONUTF8=1 python -m pytest -q (7478 passed, 8 skipped, 2 xfailed)

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show another implementation of the CLDR/LDML doing this? With this sort of change I'd really love to be sure.

Comment thread babel/numbers.py Resolved
@akx
akx force-pushed the codex/scientific-exponent-grouping branch from ed77862 to ee88720 Compare October 30, 2026 11:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect expected value in exponent grouping test

2 participants