We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a79544 commit 9c50eb2Copy full SHA for 9c50eb2
2 files changed
src/humanize/number.py
@@ -2,6 +2,7 @@
2
3
"""Humanizing functions for numbers."""
4
5
+import math
6
import re
7
from fractions import Fraction
8
@@ -185,12 +186,12 @@ def intword(value, format="%.1f"):
185
186
chopped = value / float(powers[ordinal])
187
singular, plural = human_powers[ordinal]
188
return (
- " ".join([format, ngettext(singular, plural, chopped)])
189
+ " ".join([format, ngettext(singular, plural, math.ceil(chopped))])
190
) % chopped
191
else:
192
singular, plural = human_powers[ordinal - 1]
193
194
195
196
return str(value)
197
tests/test_i18n.py
@@ -47,6 +47,28 @@ def test_intcomma():
47
assert humanize.intcomma(number) == "10,000,000"
48
49
50
+@pytest.mark.parametrize(
51
+ ("locale", "number", "expected_result"),
52
+ (
53
+ ("es_ES", 1000000, "1.0 millón"),
54
+ ("es_ES", 3500000, "3.5 millones"),
55
+ ("es_ES", 1000000000, "1.0 billón"),
56
+ ("es_ES", 1200000000, "1.2 billones"),
57
+ ("es_ES", 1000000000000, "1.0 trillón"),
58
+ ("es_ES", 6700000000000, "6.7 trillones"),
59
+ ),
60
+)
61
+def test_intword_plurals(locale, number, expected_result):
62
+ try:
63
+ humanize.i18n.activate(locale)
64
+ except FileNotFoundError:
65
+ pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
66
+ else:
67
+ assert humanize.intword(number) == expected_result
68
+ finally:
69
+ humanize.i18n.deactivate()
70
+
71
72
def test_default_locale_path_defined__file__():
73
i18n = importlib.import_module("humanize.i18n")
74
assert i18n._get_default_locale_path() is not None
0 commit comments