Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/fsize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __format__(self, format_spec: str) -> str:
raise AssertionError(f"unhandled unit: {unit!r}")
n = self.real / self._convert ** _UNIT_POWERS[unit]

log_digits = math.ceil(math.log10(n)) if n > 0 else 0
log_digits = math.floor(math.log10(n)) + 1 if n > 0 else 0
out_format_spec = (
f"{fill}{align}{width}{grouping}"
+ "."
Expand Down
7 changes: 7 additions & 0 deletions tests/test_fsize_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ def test_format_empty_spec():
assert format(z, "") == str(z)


def test_format_no_scientific_notation():
"""Test that exact powers of 10 do not produce scientific notation."""
assert format(FSize(10 * 1024), "K") == "10"
assert format(FSize(100 * 1024), "K") == "100"
assert format(FSize(1000 * 1024), "K") == "1000"


def test_format_all_units():
"""Test that every unit in _UNIT_POWERS works via format."""
# Binary FSize (1 EiB)
Expand Down
Loading