Skip to content

Commit

Permalink
bits: improve human_readable
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Jarry <[email protected]>
  • Loading branch information
rjarry committed Apr 18, 2024
1 parent cbcf58d commit eca3fc3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sosviz/bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def bit_list(bit_ids: typing.Set[int]) -> str:


def human_readable(value: float, order: int = 1000) -> str:
units = ("K", "M", "G")
units = ("K", "M", "G", "T", "P")
i = 0
unit = ""
while value >= order and i < len(units):
Expand All @@ -77,6 +77,8 @@ def human_readable(value: float, order: int = 1000) -> str:
i += 1
if unit == "":
return str(value)
if order == 1024:
unit += "i"
if value < 100 and value % 1 > 0:
return f"{value:.1f}{unit}"
return f"{value:.0f}{unit}"

0 comments on commit eca3fc3

Please sign in to comment.