diff --git a/pydantic/types.py b/pydantic/types.py index 6b3c14f..11de7b8 100644 --- a/pydantic/types.py +++ b/pydantic/types.py @@ -694,7 +694,10 @@ class ByteSize(int): num = float(self) for unit in units: if abs(num) < divisor: - return f'{num:0.1f}{unit}' + if unit == 'B': + return f'{num:0.0f}{unit}' + else: + return f'{num:0.1f}{unit}' num /= divisor return f'{num:0.1f}{final_unit}' diff --git a/tests/test_types.py b/tests/test_types.py index 1d7603a..b8442f7 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -3252,9 +3252,9 @@ def test_frozenset_field_not_convertible(): @pytest.mark.parametrize( 'input_value,output,human_bin,human_dec', ( - ('1', 1, '1.0B', '1.0B'), - ('1.0', 1, '1.0B', '1.0B'), - ('1b', 1, '1.0B', '1.0B'), + ('1', 1, '1B', '1B'), + ('1.0', 1, '1B', '1B'), + ('1b', 1, '1B', '1B'), ('1.5 KB', int(1.5e3), '1.5KiB', '1.5KB'), ('1.5 K', int(1.5e3), '1.5KiB', '1.5KB'), ('1.5 MB', int(1.5e6), '1.4MiB', '1.5MB'),