js实现流量单位的转换

function bytesToSize(bytes) {
    if (bytes === 0) return '0 B';
    var k = 1000, // or 1024
        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
        i = Math.floor(Math.log(bytes) / Math.log(k));
 
   return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

借鉴与:https://blog.csdn.net/weixin_34198797/article/details/86348514

posted on 2020-01-08 15:02  麻烦ing  阅读(999)  评论(0编辑  收藏  举报

导航