Skip to content

Instantly share code, notes, and snippets.

View imchrislawrence's full-sized avatar

Chris Lawrence imchrislawrence

View GitHub Profile
@imchrislawrence
imchrislawrence / formatBytes.js
Created November 26, 2020 17:15 — forked from zentala/formatBytes.js
Convert size in bytes to human readable format (JavaScript)
function formatBytes(bytes,decimals) {
if(bytes == 0) return '0 Bytes';
var k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
// Usage:

Keybase proof

I hereby claim:

  • I am imchrislawrence on github.
  • I am imchrislawrence (https://keybase.io/imchrislawrence) on keybase.
  • I have a public key ASAa6psjHjJDW7aJtzdXH1UfLfFYbMp9tbZrG5sF46zSsQo

To claim this, I am signing this object: