SOURCE

    function getfilesize(size) {
        if (!size)
            return 0;
 
        var num = 1024.00; //byte
 
        if (size < num)
            return size + "B";
        if (size < Math.pow(num, 2))
            return (size / num).toFixed(2) + "K"; //kb
        if (size < Math.pow(num, 3))
            return (size / Math.pow(num, 2)).toFixed(2) + "M"; //M
        if (size < Math.pow(num, 4))
            return (size / Math.pow(num, 3)).toFixed(2) + "G"; //G
        return (size / Math.pow(num, 4)).toFixed(2) + "T"; //T
    }

    // getfilesize(500000)

    console.log(getfilesize(500000))
console 命令行工具 X clear

                    
>
console