Forked from yufan-liu/js - file size human readable
Last active
November 13, 2018 14:43
-
-
Save zhuifeng1017/81a0892a676856de1d0730f68daf8174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function humanFileSize(size) { | |
if(size==0){ | |
return '0B'; | |
} | |
var i = Math.floor( Math.log(size) / Math.log(1024) ); | |
return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment