From eca3fc37c5b676334078366453fdb2d0d930c87b Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 18 Apr 2024 23:08:04 +0200 Subject: [PATCH] bits: improve human_readable Signed-off-by: Robin Jarry --- sosviz/bits.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sosviz/bits.py b/sosviz/bits.py index 9685cbf..2e1b501 100644 --- a/sosviz/bits.py +++ b/sosviz/bits.py @@ -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): @@ -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}"