From 5fad65960c1512b80c96a93dfe47d892fba655f0 Mon Sep 17 00:00:00 2001 From: zhongzm Date: Wed, 15 Jan 2025 18:09:07 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E9=80=9F=E7=8E=87=E6=8D=A2?= =?UTF-8?q?=E7=AE=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/units.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/units.ts b/src/utils/units.ts index 4e0e39d..d9e78a0 100644 --- a/src/utils/units.ts +++ b/src/utils/units.ts @@ -5,8 +5,8 @@ export const bandwidthUnits: BandwidthUnit[] = ['Kbps', 'Mbps', 'Gbps']; export const bandwidthFactors: Record = { Kbps: 1, - Mbps: 1000, - Gbps: 1000000 + Mbps: 1024, + Gbps: 1048576 }; export function convertBandwidth(value: number, fromUnit: BandwidthUnit, toUnit: BandwidthUnit): number { @@ -16,10 +16,10 @@ export function convertBandwidth(value: number, fromUnit: BandwidthUnit, toUnit: } export function formatBandwidth(kbpsValue: number): { value: number; unit: BandwidthUnit } { - if (kbpsValue >= 1000000) { - return { value: kbpsValue / 1000000, unit: 'Gbps' }; - } else if (kbpsValue >= 1000) { - return { value: kbpsValue / 1000, unit: 'Mbps' }; + if (kbpsValue >= 1048576) { + return { value: kbpsValue / 1048576, unit: 'Gbps' }; + } else if (kbpsValue >= 1024) { + return { value: kbpsValue / 1024, unit: 'Mbps' }; } return { value: kbpsValue, unit: 'Kbps' }; }