mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 23:11:37 +08:00
10 lines
373 B
TypeScript
10 lines
373 B
TypeScript
|
|
/**
|
||
|
|
* 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);
|
||
|
|
}
|