//文件大小转换
function bytesToSize(bytes) {
    if (bytes === 0) return '0 B';

    var k = 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(4) + ' ' + sizes[i];
    //toPrecision(3) 后面保留一位小数,如1.0GB
  //return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

 

相关文章:

  • 2022-01-19
  • 2022-02-08
  • 2021-12-12
  • 2022-02-07
  • 2022-12-23
  • 2022-01-11
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案