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' }; }