Skip to content

Instantly share code, notes, and snippets.

View guevaraj31's full-sized avatar
🏠
Working from home

Jesus Guevara guevaraj31

🏠
Working from home
View GitHub Profile
@lanqy
lanqy / bytesToSize.js
Created March 19, 2013 03:05
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};