Convert Filesize Bytes to Readable String in Javascript
1 2 3 4 5 6 7 |
function readablizeBytes(bytes) {
var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
var e = Math.floor(Math.log(bytes)/Math.log(1024));
return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
}
readablizeBytes(5000); // 4.88 kb
|
Posted by holin At January 07, 2009 12:33
请登录以发表评论。