I\'m using this function to convert a file size in bytes to a human-readable file size:
function getReadableFileSizeString(fileSizeInBytes) { var i = -1;
sizeOf = function (bytes) { if (bytes == 0) { return "0.00 B"; } var e = Math.floor(Math.log(bytes) / Math.log(1024)); return (bytes/Math.pow(1024, e)).toFixed(2)+' '+' KMGTP'.charAt(e)+'B'; }
sizeOf(2054110009); //=> "1.91 GB" sizeOf(7054110); //=> "6.73 MB" sizeOf( (3*1024*1024) ); //=> "3.00 MB"
sizeOf(2054110009); //=> "1.91 GB"
sizeOf(7054110); //=> "6.73 MB"
sizeOf( (3*1024*1024) ); //=> "3.00 MB"