Merge pull request #111 from snikket-im/fix/byte-scaling

Fix corner cases of byte number formatting
This commit is contained in:
Matthew Wild
2022-01-17 15:47:57 +00:00
committed by GitHub

View File

@@ -53,11 +53,14 @@ def circle_name(c: typing.Any) -> str:
def format_bytes(n: float) -> str:
scale = math.floor(math.log(n, 1024))
try:
scale = max(math.floor(math.log(n, 1024)), 0)
except ValueError:
scale = 0
try:
unit = BYTE_UNIT_SCALE_MAP[scale]
factor = 1024**scale
except ValueError:
except IndexError:
unit = "TiB"
factor = 1024**4
if factor > 1: