Skip to content

Commit c11c08a

Browse files
authored
Fix regression in naturalsize for float (#240)
2 parents a0602c7 + 11e62ee commit c11c08a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/humanize/filesize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def naturalsize(
9494
return f"{bytes_} Byte"
9595

9696
if abs_bytes < base:
97-
return f"{bytes_}B" if gnu else f"{bytes_} Bytes"
97+
return f"{int(bytes_)}B" if gnu else f"{int(bytes_)} Bytes"
9898

9999
for i, s in enumerate(suffix, 2):
100100
unit = base**i

tests/test_filesize.py

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
([3000, False, True, "%.3f"], "2.930K"),
7474
([3000000000, False, True, "%.0f"], "3G"),
7575
([10**26 * 30, True, False, "%.3f"], "2.423 RiB"),
76+
([1.123456789], "1 Bytes"),
77+
([1.123456789 * 10**3], "1.1 kB"),
78+
([1.123456789 * 10**6], "1.1 MB"),
79+
([1.123456789, False, True], "1B"),
80+
([1.123456789 * 10**3, False, True], "1.1K"),
81+
([1.123456789 * 10**6, False, True], "1.1M"),
7682
],
7783
)
7884
def test_naturalsize(test_args: list[int] | list[int | bool], expected: str) -> None:

0 commit comments

Comments
 (0)