diff --git a/src/humanize/filesize.py b/src/humanize/filesize.py index bdadd55..5650d02 100644 --- a/src/humanize/filesize.py +++ b/src/humanize/filesize.py @@ -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 diff --git a/tests/test_filesize.py b/tests/test_filesize.py index fbb662a..cf4a002 100644 --- a/tests/test_filesize.py +++ b/tests/test_filesize.py @@ -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: