You've already forked snikket-web-portal
Merge pull request #111 from snikket-im/fix/byte-scaling
Fix corner cases of byte number formatting
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user