Skip to content

Instantly share code, notes, and snippets.

@K-Francis-H
Created February 3, 2021 19:36
Show Gist options
  • Select an option

  • Save K-Francis-H/8b112e9740141c808287269da6ba4b74 to your computer and use it in GitHub Desktop.

Select an option

Save K-Francis-H/8b112e9740141c808287269da6ba4b74 to your computer and use it in GitHub Desktop.
function prettySize(bytes){
let index = 0;
let suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
while(bytes > 1000){
bytes = bytes/1000;
index++;
}
return bytes.toFixed(2)+suffixes[index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment