上下行统计以及转换单位
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user