JavaScript bytes to human readable bytes, kilobytes, megabytes, etc.
function prettySize(bytes){ var units =['bytes','kb','MB','GB','TB','PB']; var e =Math.floor(Math.log(bytes)/Math.log(1024)); var size =(bytes /Math.pow(1024,Math.floor(e))).toFixed(2); var unit = units[e]; return size +' '+ unit; }
1 comment
Thanks!
Leave a Reply