Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Last active August 29, 2015 14:00
Show Gist options
  • Save mithrandi/11376644 to your computer and use it in GitHub Desktop.
Save mithrandi/11376644 to your computer and use it in GitHub Desktop.
suffixes = ('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
def saneDataSize(size):
index = int(floor(log(abs(size), 1024)))
index = min(index, len(suffixes) - 1)
index = max(index, 0)
factor = 1024 ** index
return '%0.3f %s' % (float(size) / factor, suffixes[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment