Skip to content

Instantly share code, notes, and snippets.

@md-riaz
Created February 9, 2021 04:46
Show Gist options
  • Save md-riaz/c31803b0fdcc7b9a51e6e0ade5243e98 to your computer and use it in GitHub Desktop.
Save md-riaz/c31803b0fdcc7b9a51e6e0ade5243e98 to your computer and use it in GitHub Desktop.
function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment