diff --git a/static/common.js b/static/common.js index 64c272c..ac8c3c8 100644 --- a/static/common.js +++ b/static/common.js @@ -61,15 +61,15 @@ } function fmtBytes(n) { - if (n == null) return "-"; - const x = Number(n); - if (!isFinite(x)) return "-"; - for (const unit of ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]) { - if (Math.abs(x) < 1024 || unit === "PiB") - return unit === "B" ? `${x} B` : `${x.toFixed(1)} ${unit}`; - n = x / 1024; + let x = Number(n); + if (n == null || !isFinite(x)) return "-"; + const units = ["B", "KB", "MB", "GB", "TB", "PB"]; + let i = 0; + while (Math.abs(x) >= 1000 && i < units.length - 1) { + x /= 1000; + i++; } - return `${n.toFixed(1)} PiB`; + return i === 0 ? `${Math.round(x)} ${units[i]}` : `${x.toFixed(1)} ${units[i]}`; } function fmtTime(s) {