From 72f71688939c0fbaddb847796f3ebb8bd4463243 Mon Sep 17 00:00:00 2001 From: jialin Date: Tue, 29 Jul 2025 18:39:04 +0800 Subject: [PATCH] fix: adjust precision for big size --- src/utils/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index a7720267..41f4abb3 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -22,7 +22,7 @@ export const handleBatchRequest = async ( }; export const convertFileSize = ( - sizeInBytes?: number, + sizeInBytes: number, prec = 1, allowEmpty = false ): string | number => { @@ -31,6 +31,7 @@ export const convertFileSize = ( const fmt = 1024; const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; + const precs = [0, 1, 1, 2, 2]; // precision for each unit let size = sizeInBytes; let unitIndex = 0; @@ -39,7 +40,7 @@ export const convertFileSize = ( unitIndex++; } - return `${_.round(size, prec)} ${units[unitIndex]}`; + return `${_.round(size, precs[unitIndex])} ${units[unitIndex]}`; }; export const platformCall = () => {