Skip to content

Commit

Permalink
Fix memory calculation algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 5, 2025
1 parent bb05d9d commit 70bc790
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pyarchitecture/squire.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ def size_converter(byte_size: int | float) -> str:
str:
Converted human-readable size.
"""
if byte_size:
if byte_size > 0:
size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
index = int(math.floor(math.log(byte_size, 1024)))
return (
f"{format_nos(round(byte_size / pow(1024, index), 2))} {size_name[index]}"
)
index = 0
while byte_size >= 1024 and index < len(size_name) - 1:
byte_size /= 1024
index += 1
return f"{format_nos(round(byte_size, 2))} {size_name[index]}"
return "0 B"


Expand Down

0 comments on commit 70bc790

Please sign in to comment.