Last active
October 11, 2016 00:07
-
-
Save evanfoster/9dc55b0366a574c14d8eb18a17855f8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SI units, 1000 base | |
def sizeof_fmt_si(num, suffix='B'): | |
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']: | |
if abs(num) < 1000.0: | |
return "%3.1f%s%s" % (num, unit, suffix) | |
num /= 1000.0 | |
return "%.1f%s%s" % (num, 'Yi', suffix) | |
# Binary prefix, 1024 base | |
def sizeof_fmt_binary(num, suffix='B'): | |
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']: | |
if abs(num) < 1024.0: | |
return "%3.1f%s%s" % (num, unit, suffix) | |
num /= 1024.0 | |
return "%.1f%s%s" % (num, 'Yi', suffix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment