Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Created June 3, 2018 17:39
Show Gist options
  • Save luislobo14rap/4c873c32ee4b6cb0789913c79e6f5245 to your computer and use it in GitHub Desktop.
Save luislobo14rap/4c873c32ee4b6cb0789913c79e6f5245 to your computer and use it in GitHub Desktop.
// formatBytes.min.js v1, https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
function formatBytes(t,B){if(0==t)return'0 Bytes';var o=B||2,a=Math.floor(Math.log(t)/Math.log(1024));return parseFloat((t/Math.pow(1024,a)).toFixed(o))+' '+['Bytes','KB','MB','GB','TB','PB','EB','ZB','YB'][a]};
@luislobo14rap
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment