优化Again
This commit is contained in:
@@ -9,7 +9,8 @@ function formatBytes(bytes, decimals = 2) {
|
||||
if (!bytes || bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k));
|
||||
let i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k));
|
||||
i = Math.max(0, Math.min(i, sizes.length - 1));
|
||||
const value = bytes / Math.pow(k, i);
|
||||
return value.toFixed(decimals) + ' ' + sizes[i];
|
||||
}
|
||||
@@ -21,7 +22,8 @@ function formatBandwidth(bytesPerSec, decimals = 2) {
|
||||
if (!bytesPerSec || bytesPerSec === 0) return '0 B/s';
|
||||
const k = 1024;
|
||||
const sizes = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s'];
|
||||
const i = Math.floor(Math.log(Math.abs(bytesPerSec)) / Math.log(k));
|
||||
let i = Math.floor(Math.log(Math.abs(bytesPerSec)) / Math.log(k));
|
||||
i = Math.max(0, Math.min(i, sizes.length - 1));
|
||||
const value = bytesPerSec / Math.pow(k, i);
|
||||
return value.toFixed(decimals) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user