Skip to content

Instantly share code, notes, and snippets.

@MWers
Created September 5, 2013 06:21
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 MWers/6446651 to your computer and use it in GitHub Desktop.
Save MWers/6446651 to your computer and use it in GitHub Desktop.
var SizePrefixes = ' KMGTPEZYXWVU';
GetHumanSize = function(size) {
if(size <= 0) return '0';
var t2 = Math.min(Math.round(Math.log(size)/Math.log(1024)), 12);
return (Math.round(size * 100 / Math.pow(1024, t2)) / 100) +
SizePrefixes.charAt(t2).replace(' ', '') + 'B';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment