Skip to content

Instantly share code, notes, and snippets.

@null4bl3
Created May 14, 2018 13:18
Show Gist options
  • Save null4bl3/80e34b6da56d2c69180984de07c4bfe9 to your computer and use it in GitHub Desktop.
Save null4bl3/80e34b6da56d2c69180984de07c4bfe9 to your computer and use it in GitHub Desktop.
return a ceil + parseint value
formatBytes(bytes) {
if (bytes < 1024) {
return bytes + " Bytes";
} else if (bytes < 1048576) {
return parseInt(Math.ceil(bytes / 1024).toFixed(3), 10) + " KB";
} else if (bytes < 1073741824) {
return parseInt(Math.ceil(bytes / 1048576).toFixed(3), 10) + " MB";
} else {
return parseInt(Math.ceil(bytes / 1073741824).toFixed(3), 10) + " GB";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment