Skip to content

Instantly share code, notes, and snippets.

@ewebdev
Created February 26, 2014 14:27
Show Gist options
  • Save ewebdev/9230351 to your computer and use it in GitHub Desktop.
Save ewebdev/9230351 to your computer and use it in GitHub Desktop.
function formatFileSize(bytes) {
var val = bytes / 1024,
suffix;
if (val < 1000) {
suffix = 'KB';
} else {
val = val / 1024;
if (val < 1000) {
suffix = 'MB';
} else {
val = val / 1024;
if (val < 1000) {
suffix = 'GB';
} else {
val = val / 1024;
suffix = 'TB';
}
}
}
return numericFormatters.round(val, 2) + suffix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment