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])