Skip to content

Commit

Permalink
Merge pull request #87 from hugovk/fix-intword-thousand-decillion
Browse files Browse the repository at this point in the history
Fixes #86
  • Loading branch information
hugovk committed Jan 28, 2023
2 parents 6fde596 + 8705e29 commit 4304f46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/humanize/number.py
Expand Up @@ -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 (
Expand Down
3 changes: 3 additions & 0 deletions tests/test_number.py
Expand Up @@ -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),
Expand Down

0 comments on commit 4304f46

Please sign in to comment.