Skip to content

Commit 00b0d3a

Browse files
author
Daniel Gillet
committed
Fix intword format regression
Remove unused code.
1 parent 6793aee commit 00b0d3a

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/humanize/number.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,11 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
257257
if not largest_ordinal and rounded_value * power == powers[ordinal + 1]:
258258
# After rounding, we end up just at the next power
259259
ordinal += 1
260-
power = powers[ordinal]
261260
rounded_value = 1.0
262261

263262
singular, plural = human_powers[ordinal]
264263
unit = _ngettext(singular, plural, math.ceil(rounded_value))
265-
return f"{negative_prefix}{rounded_value} {unit}"
264+
return f"{negative_prefix}{format % rounded_value} {unit}"
266265

267266

268267
def apnumber(value: NumberOrString) -> str:

tests/test_number.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def test_intword_powers() -> None:
128128
([-math.inf], "-Inf"),
129129
(["nan"], "NaN"),
130130
(["-inf"], "-Inf"),
131+
(["1234567", "%.0f"], "1 million"),
132+
(["1234567", "%.1f"], "1.2 million"),
133+
(["1234567", "%.2f"], "1.23 million"),
134+
(["1234567", "%.3f"], "1.235 million"),
135+
(["999500", "%.0f"], "1 million"),
136+
(["999499", "%.0f"], "999 thousand"),
131137
],
132138
)
133139
def test_intword(test_args: list[str], expected: str) -> None:

0 commit comments

Comments
 (0)