//文件大小转换 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]; }
时间: 2024-12-17 11:53:59