Skip to content

Honor minimum significant digits when formatting zero - #1494

Open
manav4u wants to merge 1 commit into
python-babel:masterfrom
manav4u:fix-zero-significant-digit-precision
Open

manav4u wants to merge 1 commit into
python-babel:masterfrom
manav4u:fix-zero-significant-digit-precision

Conversation

@manav4u

@manav4u manav4u commented Nov 26, 2026

Copy link
Copy Markdown

Zero currently renders as 0.0 for most significant-digit patterns, regardless of the minimum. For example:

format_decimal(0, '@#', locale='en_US')  # '0.0', expected '0'
format_decimal(0, '@@@', locale='en_US')  # '0.0', expected '0.00'

Handle zero before the exponent/scaling calculation. Keep one integer zero and pad to the minimum significant-digit count; the existing caller still handles signs, separators and affixes.

Tests cover mandatory and optional digits, integer and Decimal zero inputs, signed zero, a comma separator and an explicit negative subpattern. The new regressions produce 18 failures on the unchanged base. Both full patched suites pass on Python 3.10 and 3.14 with TZ=UTC: 8316 passed, 3 skipped, 2 xfailed. Ruff and diff checks pass.

This is separate from #1388's nonzero carry adjustment. An independent in-memory composition with that change matches 63336 rational-oracle cases. ICU 78 matches zero precision; pre-existing localized minus/bidi differences are not part of this patch.

This fix was found and prepared with AI assistance. The reproductions and tests above were run locally. No related downstream issue was found.

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.

2 participants