Skip to content

Commit

Permalink
🐛 [-bug] Printing bytes as integer rather than float (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrownell authored Jun 12, 2024
2 parents d897b63 + 1ae11eb commit 7c32321
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dbrownell_Common/PathEx.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ def GetSizeDisplay(
else:
assert False, path_or_num_bytes # pragma: no cover

if num_bytes < 1024.0:
return "{} B".format(int(num_bytes))

num_bytes /= 1024.0

for unit in [
"",
"K",
"M",
"G",
Expand Down
2 changes: 1 addition & 1 deletion tests/PathEx_UnitTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_GetCommonPath():

# ----------------------------------------------------------------------
def test_GetSizeDisplay():
assert GetSizeDisplay(1000) == "1000.0 B"
assert GetSizeDisplay(1000) == "1000 B"
assert GetSizeDisplay(10000) == "9.8 KB"
assert GetSizeDisplay(100000) == "97.7 KB"
assert GetSizeDisplay(1000000) == "976.6 KB"
Expand Down

0 comments on commit 7c32321

Please sign in to comment.