ITADN

Formatting currencies in the compact format fails for 1000 in locale nl_NL

#1245Closedbartbroere 创建于 2026-01-14
bugarea/numbers
B
bartbroerecommented
I was formatting monetary amounts in the compact format with `babel.numbers.format_compact_currency`. Using the Dutch locale (`nl_NL`) I noticed that it failed for exactly one thousand euros. Add or remove a penny and it works again. ```python from babel.numbers import format_compact_currency print(format_compact_currency(1000.01, 'EUR', locale='nl')) # € 1K print(format_compact_currency(1000, 'EUR', locale='nl')) # Traceback (most recent call last): # File "/Users/bart/workspace/babel/reproduce_thousand_nl.py", line 6, in <module> # print(format_compact_currency(1000, 'EUR', locale='nl')) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # File "/Users/bart/workspace/babel/babel/numbers.py", line 924, in format_compact_currency # number, format = _get_compact_format(number, compact_format, locale, fraction_digits) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # File "/Users/bart/workspace/babel/babel/numbers.py", line 693, in _get_compact_format # format = compact_format[plural_form][str(magnitude)] # ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^ # File "/Users/bart/workspace/babel/babel/localedata.py", line 264, in __getitem__ # orig = val = self._data[key] # ~~~~~~~~~~^^^^^ # KeyError: '1000' ``` After reproducing this, I also checked the locale `nl`, and `nl_BE` and those have the same issues. I'm willing to contribute a fix, but people that are more familiar with the codebase might be able to do so quicker.
关闭于 2026-01-31 2 条评论