From 37f8a33a86ec7e8e5b035a25e4df379d806220a0 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Thu, 20 Jan 2022 22:02:06 +0700 Subject: [PATCH] formatter --- program/utils/formatters.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 program/utils/formatters.py diff --git a/program/utils/formatters.py b/program/utils/formatters.py new file mode 100644 index 0000000..d97f7c3 --- /dev/null +++ b/program/utils/formatters.py @@ -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])