Skip to content

Compact decimal plural forms use the value before rounding #1429

Open

Description

@0718lol

Overview Description

Compact decimal plural selection uses the scaled value before rounding, even when the displayed value has no fractional digits. This gives the wrong unit form for ordinary inputs in Russian, Polish, Czech, and French.

Steps to Reproduce

from babel.numbers import format_compact_decimal

for locale, value in [('ru', 1100), ('pl', 1900), ('cs', 1100), ('fr', 1900)]:
    print(locale, format_compact_decimal(value, format_type='long', fraction_digits=0, locale=locale))

Actual Results

ru 1 тысячи
pl 2 tysiąca
cs 1 tisíce
fr 2 millier

Expected Results

ru 1 тысяча
pl 2 tysiące
cs 1 tisíc
fr 2 mille

The plural form should correspond to the displayed rounded value. As an independent comparison, Node's Intl.NumberFormat(locale, {notation: 'compact', compactDisplay: 'long', maximumFractionDigits: 0}) produces these expected outputs.

Reproducibility

Reproduced on master at 63c168e, Python 3.12.15 on macOS, with CLDR 48.2 generated using scripts/download_import_cldr.py.

Additional Information

_get_compact_format computes rounded, but passes abs(scaled) to locale.plural_form. The displayed result also drops optional fractional zeros: e.g. Russian 1010 with fraction_digits=1 displays 1, rather than 1.0, so those zeros should not affect plural selection.

This differs from #1301: no change of magnitude is needed to reproduce it. This report was investigated with Codex assistance; the examples above were executed locally.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions