From f76890cc56f4a5c1e8ca1f37fdd83568a288540b Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Thu, 24 Nov 2022 11:11:31 +0800
Subject: [PATCH] fix: parse bytes base 1024

---
 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 2e7eacf..6bb1a8c 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 (num < 1000) return [`${Math.round(num)}`, "B"];
-  const exp = Math.min(Math.floor(Math.log10(num) / 3), UNITS.length - 1);
-  const ret = (num / Math.pow(1000, exp)).toPrecision(3);
+  const exp = Math.min(Math.floor(Math.log2(num) / 10), UNITS.length - 1);
+  const ret = (num / Math.pow(1024, exp)).toPrecision(3);
   const unit = UNITS[exp];
 
   return [ret, unit];
-- 
GitLab