From 45c20e507a90adbd6c0b80ee767f9fe3ef5ceb9b Mon Sep 17 00:00:00 2001 From: lai <371757574@qq.com> Date: Mon, 29 Jan 2024 00:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8DUPF=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E6=95=B0=E7=A9=BA=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/parse-utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/parse-utils.ts b/src/utils/parse-utils.ts index 83271e86..b5ee9498 100644 --- a/src/utils/parse-utils.ts +++ b/src/utils/parse-utils.ts @@ -155,6 +155,9 @@ export function parseSizeFromKbs(sizeByte: number, timeInterval: number): any { * @returns */ export function formatBytes(bytes: number): string { + if (bytes === 0) { + return '0 B'; // 处理 bytes 为 0 的情况 + } const units = ['B', 'KB', 'MB', 'GB', 'TB']; const unitIndex = Math.floor(Math.log2(bytes) / 10); const result =(bytes / Math.pow(1024, unitIndex)).toFixed(2) + ' ' + units[unitIndex];