Skip to content

Commit

Permalink
Fix regression in naturalsize for float
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 17, 2025
1 parent a0602c7 commit 11e62ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/humanize/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def naturalsize(
return f"{bytes_} Byte"

if abs_bytes < base:
return f"{bytes_}B" if gnu else f"{bytes_} Bytes"
return f"{int(bytes_)}B" if gnu else f"{int(bytes_)} Bytes"

for i, s in enumerate(suffix, 2):
unit = base**i
Expand Down
6 changes: 6 additions & 0 deletions tests/test_filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
([3000, False, True, "%.3f"], "2.930K"),
([3000000000, False, True, "%.0f"], "3G"),
([10**26 * 30, True, False, "%.3f"], "2.423 RiB"),
([1.123456789], "1 Bytes"),
([1.123456789 * 10**3], "1.1 kB"),
([1.123456789 * 10**6], "1.1 MB"),
([1.123456789, False, True], "1B"),
([1.123456789 * 10**3, False, True], "1.1K"),
([1.123456789 * 10**6, False, True], "1.1M"),
],
)
def test_naturalsize(test_args: list[int] | list[int | bool], expected: str) -> None:
Expand Down

0 comments on commit 11e62ee

Please sign in to comment.