From ff0de29f17fd81ceda710156565343c85aee74a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9D=A4=E6=98=AF=E7=BA=B1=E9=9B=BE=E9=85=B1=E5=93=9F?= =?UTF-8?q?=EF=BD=9E?= <49941141+Dragon1573@users.noreply.github.com> Date: Sat, 6 Dec 2025 09:00:04 +0800 Subject: [PATCH] Fixes traffic parsing for small values (#5737) - Unified handler to IEC standard. - Change handler to parse number in a unified style, even with number less than 1000. Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com> --- src/utils/parse-traffic.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/parse-traffic.ts b/src/utils/parse-traffic.ts index 514d24fe2..c884262a2 100644 --- a/src/utils/parse-traffic.ts +++ b/src/utils/parse-traffic.ts @@ -2,8 +2,8 @@ const UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const parseTraffic = (num?: number) => { if (typeof num !== "number") return ["NaN", ""]; - if (num < 1000) return [`${Math.round(num)}`, "B"]; - const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1); + const exp = + num < 1 ? 0 : Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1); const dat = num / Math.pow(1024, exp); const ret = dat >= 1000 ? dat.toFixed(0) : dat.toPrecision(3); const unit = UNITS[exp];