Math.log()对数的妙用

 

###对数log 的妙用。。。

 formatBytes(bytes) {

        if (bytes === '0' || isNaN(bytes)) return '';

        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(1) + " " + s[e];

    },

猜你喜欢

转载自www.cnblogs.com/softwarelanguagebs/p/10758723.html