Math.log()对数的妙用

Posted softwarelanguagebs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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];

    },

以上是关于Math.log()对数的妙用的主要内容,如果未能解决你的问题,请参考以下文章