formatter

This commit is contained in:
levina 2022-01-20 22:02:06 +07:00 committed by GitHub
parent b74a52a6db
commit 37f8a33a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,10 @@
def bytes(size: float) -> str:
if not size:
return ""
power = 1024
t_n = 0
power_dict = {0: " ", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power:
size /= power
t_n += 1
return "{:.2f} {}B".format(size, power_dict[t_n])