上下行统计以及转换单位

This commit is contained in:
lai
2024-01-26 17:02:11 +08:00
parent 231d0381d1
commit 308a66b925
5 changed files with 108 additions and 79 deletions

View File

@@ -148,3 +148,15 @@ export function parseSizeFromKbs(sizeByte: number, timeInterval: number): any {
return [(realBit / 1000 / 1000).toFixed(2), ' Mbits/sec'];
}
/**
* 字节数转换单位
* @param sizeByte 数值大小
* @returns
*/
export function formatBytes(bytes: number): string {
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
const unitIndex = Math.floor(Math.log2(bytes) / 10);
const result =(bytes / Math.pow(1024, unitIndex)).toFixed(2) + ' ' + units[unitIndex];
return result;
}