fix:速率换算修改
This commit is contained in:
@@ -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' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user