From 75c921b466dc3aceca80744fa131ea2e35779380 Mon Sep 17 00:00:00 2001 From: Alechron Date: Tue, 15 Sep 2026 05:17:35 +0000 Subject: [PATCH] fix(traffic): avoid scientific notation in traffic display near 1000 threshold (#7928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(traffic): avoid scientific notation in traffic display near 1000 threshold When a traffic value in any unit (KB, MB, etc.) falls in the 999.5–1000 range, toPrecision(3) rounds it to 1000 but outputs scientific notation "1.00e+3" instead of plain "1000". Check Math.round(dat) >= 1000 instead of dat >= 1000 to catch this rounding boundary. Signed-off-by: Alec * fix(traffic): avoid scientific notation in formatConnectionTraffic Signed-off-by: Alec --------- Signed-off-by: Alec --- src/components/connection/connection-row-view.ts | 2 +- src/utils/parse-traffic.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/connection/connection-row-view.ts b/src/components/connection/connection-row-view.ts index de6a22997..9e5d1ed6c 100644 --- a/src/components/connection/connection-row-view.ts +++ b/src/components/connection/connection-row-view.ts @@ -35,7 +35,7 @@ export const formatConnectionTraffic = (value?: number) => { ? 0 : Math.min(Math.floor(Math.log2(value) / 10), TRAFFIC_UNITS.length - 1) const data = value / 1024 ** exp - const text = data >= 1000 ? data.toFixed(0) : data.toPrecision(3) + const text = Math.round(data) >= 1000 ? data.toFixed(0) : data.toPrecision(3) return `${text} ${TRAFFIC_UNITS[exp]}` } diff --git a/src/utils/parse-traffic.ts b/src/utils/parse-traffic.ts index c3e3dfce9..dbd1e5704 100644 --- a/src/utils/parse-traffic.ts +++ b/src/utils/parse-traffic.ts @@ -5,7 +5,7 @@ const parseTraffic = (num?: number) => { 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 ret = Math.round(dat) >= 1000 ? dat.toFixed(0) : dat.toPrecision(3) const unit = UNITS[exp] return [ret, unit]