Skip to content

Commit 9a5156e

Browse files
committed
fix(tui): roll over compact counts to M at 999,950
Locale.number() formats the thousands value with toFixed(1), so counts from 999,950 to 999,999 rounded to 1000.0 and rendered as "1000.0K". The >= 1000000 branch could not promote them because the count itself is still below a million. It shows up in the TUI context indicator on ~1M context models as "1000.0K (100%)". Roll over at 999,950 instead, the point where one-decimal rounding first reaches 1000.0K, so those counts render as "1.0M". Closes anomalyco#33947
1 parent 8e0f1c2 commit 9a5156e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎packages/tui/src/util/locale.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function todayTimeOrDateTime(input: number): string {
2828
}
2929

3030
export function number(num: number): string {
31-
if (num >= 1000000) {
31+
// 999,950 and up round to 1000.0K at one decimal place, so roll over to M there
32+
if (num >= 999950) {
3233
return (num / 1000000).toFixed(1) + "M"
3334
} else if (num >= 1000) {
3435
return (num / 1000).toFixed(1) + "K"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { number } from "../../src/util/locale"
3+
4+
describe("util.locale.number", () => {
5+
test("formats counts below a thousand as-is", () => {
6+
expect(number(0)).toBe("0")
7+
expect(number(999)).toBe("999")
8+
})
9+
10+
test("formats thousands with a K suffix", () => {
11+
expect(number(1000)).toBe("1.0K")
12+
expect(number(1500)).toBe("1.5K")
13+
expect(number(999949)).toBe("999.9K")
14+
})
15+
16+
test("rolls over to M once the K value would round to 1000.0", () => {
17+
expect(number(999950)).toBe("1.0M")
18+
expect(number(999999)).toBe("1.0M")
19+
})
20+
21+
test("formats millions with an M suffix", () => {
22+
expect(number(1000000)).toBe("1.0M")
23+
expect(number(1500000)).toBe("1.5M")
24+
})
25+
})

0 commit comments

Comments
 (0)