Skip to content

Instantly share code, notes, and snippets.

@pawitp
Created January 28, 2015 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawitp/abd4670b8f857f8da9f0 to your computer and use it in GitHub Desktop.
Save pawitp/abd4670b8f857f8da9f0 to your computer and use it in GitHub Desktop.
def formatBytes(val):
if val >= 1000000000:
return "%0.3f Gb" % (val / 1000000000)
elif val >=1000000:
return "%0.3f Mb" % (val / 1000000)
elif val >=1000:
return "%0.3f Kb" % (val / 1000)
else:
return "%0.3f B" % val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment