2
0

fix:速率换算修改

This commit is contained in:
zhongzm
2025-01-15 18:09:07 +08:00
parent 134a417eb1
commit 5fad65960c

View File

@@ -5,8 +5,8 @@ export const bandwidthUnits: BandwidthUnit[] = ['Kbps', 'Mbps', 'Gbps'];
export const bandwidthFactors: Record<BandwidthUnit, number> = {
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' };
}