From a95df3da9fc20280ba18fef2b3cc78ee05a21d0d Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Wed, 25 Nov 2026 06:50:03 +0000 Subject: [PATCH 1/2] fix(web): a 9.996 KB file reads "10.0 KB", not "10.00 KB" --- apps/web/src/lib/formatBytes.test.ts | 5 +++++ apps/web/src/lib/formatBytes.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/web/src/lib/formatBytes.test.ts b/apps/web/src/lib/formatBytes.test.ts index 5b5d948bb59c..fc81f7295165 100644 --- a/apps/web/src/lib/formatBytes.test.ts +++ b/apps/web/src/lib/formatBytes.test.ts @@ -8,8 +8,13 @@ describe("formatBytes", () => { [1_023, "1023 B"], [1_024, "1.00 KB"], [1_536, "1.50 KB"], + [10_234, "9.99 KB"], + [10_235, "10.0 KB"], + [102_348, "99.9 KB"], + [102_350, "100 KB"], [1_047_552, "1023 KB"], [1_048_576, "1.00 MB"], + [10_480_518, "10.0 MB"], [5 * 1_024 ** 4, "5.00 TB"], [2_048 * 1_024 ** 4, "2048 TB"], ])("formats %d bytes as %s", (value, label) => { diff --git a/apps/web/src/lib/formatBytes.ts b/apps/web/src/lib/formatBytes.ts index fe6de1cdb2a1..1c1e1111f0d9 100644 --- a/apps/web/src/lib/formatBytes.ts +++ b/apps/web/src/lib/formatBytes.ts @@ -1,5 +1,9 @@ function formatScaled(value: number): string { - return value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2); + const twoDecimals = value.toFixed(2); + if (Number(twoDecimals) < 10) return twoDecimals; + const oneDecimal = value.toFixed(1); + if (Number(oneDecimal) < 100) return oneDecimal; + return value.toFixed(0); } export function formatBytes(value: number): string { From efbb515ec1ffe3185d8864a6540752e0411d4228 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 25 Nov 2026 07:48:19 +0000 Subject: [PATCH 2/2] test(web): keep only the formatBytes boundaries that roll the precision Co-Authored-By: Claude Opus 5.5 --- apps/web/src/lib/formatBytes.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/web/src/lib/formatBytes.test.ts b/apps/web/src/lib/formatBytes.test.ts index fc81f7295165..82de7bb7267c 100644 --- a/apps/web/src/lib/formatBytes.test.ts +++ b/apps/web/src/lib/formatBytes.test.ts @@ -8,13 +8,10 @@ describe("formatBytes", () => { [1_023, "1023 B"], [1_024, "1.00 KB"], [1_536, "1.50 KB"], - [10_234, "9.99 KB"], [10_235, "10.0 KB"], - [102_348, "99.9 KB"], [102_350, "100 KB"], [1_047_552, "1023 KB"], [1_048_576, "1.00 MB"], - [10_480_518, "10.0 MB"], [5 * 1_024 ** 4, "5.00 TB"], [2_048 * 1_024 ** 4, "2048 TB"], ])("formats %d bytes as %s", (value, label) => {