|
@@ -1,19 +1,25 @@
|
|
|
const ONE_KB = 1024;
|
|
|
-const units = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
|
+const ONE_MB = ONE_KB * 1024;
|
|
|
+const ONE_GB = ONE_MB * 1024;
|
|
|
+const ONE_TB = ONE_GB * 1024;
|
|
|
+const ONE_PB = ONE_TB * 1024;
|
|
|
|
|
|
function sizeFormat(size) {
|
|
|
- if (size < 0) {
|
|
|
- return "0 B";
|
|
|
- }
|
|
|
-
|
|
|
- let index = 0;
|
|
|
-
|
|
|
- while (size >= ONE_KB && index < units.length - 1) {
|
|
|
- size /= ONE_KB;
|
|
|
- index++;
|
|
|
+ if (size <= 0) return "0 B";
|
|
|
+
|
|
|
+ if (size < ONE_KB) {
|
|
|
+ return size.toFixed(0) + " B";
|
|
|
+ } else if (size < ONE_MB) {
|
|
|
+ return (size / ONE_KB).toFixed(2) + " KB";
|
|
|
+ } else if (size < ONE_GB) {
|
|
|
+ return (size / ONE_MB).toFixed(2) + " MB";
|
|
|
+ } else if (size < ONE_TB) {
|
|
|
+ return (size / ONE_GB).toFixed(2) + " GB";
|
|
|
+ } else if (size < ONE_PB) {
|
|
|
+ return (size / ONE_TB).toFixed(2) + " TB";
|
|
|
+ } else {
|
|
|
+ return (size / ONE_PB).toFixed(2) + " PB";
|
|
|
}
|
|
|
-
|
|
|
- return `${size.toFixed(index === 0 ? 0 : 2)} ${units[index]}`;
|
|
|
}
|
|
|
|
|
|
function cpuSpeedFormat(speed) {
|