Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/humanize/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ def fractional(value: NumberOrString) -> str:
frac = Fraction(number - whole_number).limit_denominator(1000)
numerator = frac.numerator
denominator = frac.denominator
if whole_number and not numerator and denominator == 1:
if not numerator and denominator == 1:
# this means that an integer was passed in
# (or variants of that integer like 1.0000)
# (or variants of that integer like 1.0000, and including 0)
return f"{whole_number:.0f}"

if not whole_number:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def test_apnumber(test_input: int | str, expected: str) -> None:
[
(1, "1"),
(2.0, "2"),
(0, "0"),
(0.0, "0"),
(4.0 / 3.0, "1 1/3"),
(5.0 / 6.0, "5/6"),
("7", "7"),
Expand Down