From 2e7ac8c8ead60bf44c2ae216251f9f8c368cb661 Mon Sep 17 00:00:00 2001 From: argszero Date: Fri, 16 Oct 2026 07:34:22 +0800 Subject: [PATCH] fix(tui): roll the compact form over to M at the rounding boundary (#55871) Co-authored-by: argszero Co-authored-by: Tarquinen <78942835+Tarquinen@users.noreply.github.com> --- packages/tui/src/util/locale.ts | 3 ++- packages/tui/test/util/locale.test.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/tui/src/util/locale.ts b/packages/tui/src/util/locale.ts index 569484e3730..ac3371eb079 100644 --- a/packages/tui/src/util/locale.ts +++ b/packages/tui/src/util/locale.ts @@ -17,7 +17,8 @@ export function datetime(input: number): string { } export function number(num: number): string { - if (num >= 1000000) { + // 999950+ would round to "1000.0K" + if (num >= 999950) { return (num / 1000000).toFixed(1) + "M" } else if (num >= 1000) { return (num / 1000).toFixed(1) + "K" diff --git a/packages/tui/test/util/locale.test.ts b/packages/tui/test/util/locale.test.ts index e3d3396884b..2d5a008f0ae 100644 --- a/packages/tui/test/util/locale.test.ts +++ b/packages/tui/test/util/locale.test.ts @@ -12,3 +12,9 @@ test("takes whole graphemes within terminal width", () => { expect(Locale.takeWidth("ab็•Œcd", 4)).toBe("ab็•Œ") expect(Locale.graphemes("a๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆb")).toEqual(["a", "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ", "b"]) }) + +test("rolls the compact form over at the rounding boundary", () => { + expect(Locale.number(999949)).toBe("999.9K") + expect(Locale.number(999950)).toBe("1.0M") + expect(Locale.number(1000000)).toBe("1.0M") +})