Something went wrong. Try again.
The agent that grows with you
Something went wrong. Try again.
373 B · 9 lines
TypeScript
12345678910/** * Format a token count as a human-readable string (e.g. 1M, 128K, 4096). * Strips trailing ".0" for clean round numbers. */export function formatTokenCount(n: number): string { if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n % 1_000_000 === 0 ? 0 : 1)}M`; if (n >= 1_000) return `${(n / 1_000).toFixed(n % 1_000 === 0 ? 0 : 1)}K`; return String(n);}