Skip to content

Commit 29bd362

Browse files
authored
Fix formatting compact currencies of exactly one thousand in several locales (#1246)
* Add a smoke test for thousands and compact currency formats * Fall back to other when formatting compact currencies
1 parent 851db43 commit 29bd362

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

babel/numbers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ def _get_compact_format(
690690
plural_form = "other"
691691
if number == 1 and "1" in compact_format:
692692
plural_form = "1"
693+
if str(magnitude) not in compact_format[plural_form]:
694+
plural_form = "other" # fall back to other as the implicit default
693695
format = compact_format[plural_form][str(magnitude)]
694696
number = rounded
695697
break

tests/test_smoke.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1.2 - 1.0, # Inaccurate float
1818
10, # Plain old integer
1919
0, # Zero
20+
1000, # A thousand (previously raised KeyError in the nl locale for compact currencies)
2021
)
2122

2223

@@ -46,6 +47,8 @@ def test_smoke_numbers(locale):
4647
assert numbers.format_decimal(number, locale=locale, numbering_system="default")
4748
assert numbers.format_currency(number, "EUR", locale=locale)
4849
assert numbers.format_currency(number, "EUR", locale=locale, numbering_system="default")
50+
assert numbers.format_compact_currency(number, "EUR", locale=locale)
51+
assert numbers.format_compact_currency(number, "EUR", locale=locale, numbering_system="default")
4952
assert numbers.format_scientific(number, locale=locale)
5053
assert numbers.format_scientific(number, locale=locale, numbering_system="default")
5154
assert numbers.format_percent(number / 100, locale=locale)

0 commit comments

Comments
 (0)