避免UPF字节数空值
This commit is contained in:
@@ -155,6 +155,9 @@ export function parseSizeFromKbs(sizeByte: number, timeInterval: number): any {
|
||||
* @returns
|
||||
*/
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) {
|
||||
return '0 B'; // 处理 bytes 为 0 的情况
|
||||
}
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user