diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts index f8e688b63..064ed2857 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts @@ -101,6 +101,11 @@ describe("humanizeBytes", () => { expect(humanizeBytes(1023)).toBe("1023B") }) + it("formats kilobytes as Ki without decimals", () => { + expect(humanizeBytes(1024)).toBe("1Ki") + expect(humanizeBytes(512 * 1024)).toBe("512Ki") + }) + it("formats megabytes as Mi without decimals", () => { expect(humanizeBytes(1024 ** 2)).toBe("1Mi") }) diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts index cee1693ef..8ed3a512e 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts @@ -33,6 +33,7 @@ export function humanizeBytes(bytes: number): string { if (bytes >= 1024 ** 4) return `${(bytes / 1024 ** 4).toFixed(1)}Ti` if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)}Gi` if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)}Mi` + if (bytes >= 1024) return `${(bytes / 1024).toFixed(0)}Ki` return `${bytes}B` }