Skip to content

Commit 4304f46

Browse files
authored
Merge pull request #87 from hugovk/fix-intword-thousand-decillion
Fixes #86
2 parents 6fde596 + 8705e29 commit 4304f46

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/humanize/number.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
243243
for ordinal_, power in enumerate(powers[1:], 1):
244244
if value < power:
245245
chopped = value / float(powers[ordinal_ - 1])
246-
if float(format % chopped) == float(10**3):
246+
powers_difference = powers[ordinal_] / powers[ordinal_ - 1]
247+
if float(format % chopped) == powers_difference:
247248
chopped = value / float(powers[ordinal_])
248249
singular, plural = human_powers[ordinal_]
249250
return (

tests/test_number.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def test_intword_powers() -> None:
115115
(["3500000000000000000000"], "3.5 sextillion"),
116116
(["8100000000000000000000000000000000"], "8.1 decillion"),
117117
(["-8100000000000000000000000000000000"], "-8.1 decillion"),
118+
([1_000_000_000_000_000_000_000_000_000_000_000_000], "1000.0 decillion"),
119+
([1_100_000_000_000_000_000_000_000_000_000_000_000], "1100.0 decillion"),
120+
([2_100_000_000_000_000_000_000_000_000_000_000_000], "2100.0 decillion"),
118121
([None], "None"),
119122
(["1230000", "%0.2f"], "1.23 million"),
120123
([10**101], "1" + "0" * 101),

0 commit comments

Comments
 (0)