Skip to content

The agent that grows with you

docs(shared): declare M as compactNumber's top rung

teknium1c3edad29baad
diff --git a/apps/shared/src/format.test.ts b/apps/shared/src/format.test.ts
index b2820fc0329..2b196673352 100644
--- a/apps/shared/src/format.test.ts
+++ b/apps/shared/src/format.test.ts
@@ -14,6 +14,7 @@ describe('compactNumber', () => {
[999_999, '1M'],
[1_000_000, '1M'],
[1_500_000, '1.5M'],
+ // `M` is the declared top rung (see format.ts): no `B`, so billions stay in M.
[1_000_000_000, '1000M']
])('%d → %s', (value, expected) => {
expect(compactNumber(value)).toBe(expected)
diff --git a/apps/shared/src/format.ts b/apps/shared/src/format.ts
index 3ecb762f03e..c00cd0cc112 100644
--- a/apps/shared/src/format.ts
+++ b/apps/shared/src/format.ts
@@ -1,6 +1,9 @@
// THE compact-number formatter — every user-facing count/token figure goes
// through here. 999 → "999", 1000 → "1k", 1230 → "1.2k", 10000 → "10k",
-// 1_500_000 → "1.5M". Do not hand-roll `/ 1000` display math elsewhere.
+// 1_500_000 → "1.5M". `M` is the top rung by design: token and cost figures
+// this renders stay well under a billion, so 1e9 reads "1000M" rather than
+// growing a `B` rung that no surface needs (and that would collide with the
+// "bytes" reading in size labels). Do not hand-roll `/ 1000` display math elsewhere.
export function compactNumber(value: null | number | undefined): string {
const num = Number(value ?? 0)