把字节转换成正常文件大小 linan0110 2024-04-10 42 阅读1分钟 function getfilesize(size) { const units = ['B', 'KB', 'MB', 'GB', 'TB']; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(2)} ${units[unitIndex]}`; }