From 8705e2967ee610a36143e2379bf091d75a1ed9b7 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 4 Jan 2023 18:05:44 +0200 Subject: [PATCH] Fix intword for 1000 decillion --- src/humanize/number.py | 3 ++- tests/test_number.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/humanize/number.py b/src/humanize/number.py index 0b5b99b..78a6f7d 100644 --- a/src/humanize/number.py +++ b/src/humanize/number.py @@ -243,7 +243,8 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str: for ordinal_, power in enumerate(powers[1:], 1): if value < power: chopped = value / float(powers[ordinal_ - 1]) - if float(format % chopped) == float(10**3): + powers_difference = powers[ordinal_] / powers[ordinal_ - 1] + if float(format % chopped) == powers_difference: chopped = value / float(powers[ordinal_]) singular, plural = human_powers[ordinal_] return ( diff --git a/tests/test_number.py b/tests/test_number.py index e66beed..bc67785 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -115,6 +115,9 @@ def test_intword_powers() -> None: (["3500000000000000000000"], "3.5 sextillion"), (["8100000000000000000000000000000000"], "8.1 decillion"), (["-8100000000000000000000000000000000"], "-8.1 decillion"), + ([1_000_000_000_000_000_000_000_000_000_000_000_000], "1000.0 decillion"), + ([1_100_000_000_000_000_000_000_000_000_000_000_000], "1100.0 decillion"), + ([2_100_000_000_000_000_000_000_000_000_000_000_000], "2100.0 decillion"), ([None], "None"), (["1230000", "%0.2f"], "1.23 million"), ([10**101], "1" + "0" * 101),