Skip to content

Commit

Permalink
round size
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Feb 16, 2024
1 parent 2f6ba0b commit 6e5d3c6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests-ng/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ def debug(txt: str):
print(f'[DEBUG] {txt}')


def size_to_str(size: float, human: bool = False) -> str:
def size_to_str(size: int, human: bool = False) -> str:
"""size to string"""
div = 1024.
suf = ['B', 'K', 'M', 'G', 'T', 'P']
if not human or size < div:
# not human
return f'{size}'
size = float(size)
for i in suf:
if size < div:
return f'{size:.1f}{i}'
return f'{round(size)}{i}'
size = size / div
sufix = suf[-1]
return f'{size:.1f}{sufix}'
return f'{round(size)}{sufix}'


def must_ignore(path: str, patterns: List[str]) -> bool:
Expand Down

0 comments on commit 6e5d3c6

Please sign in to comment.