Use Intl.NumberFormat for token formatting in SessionsInsights (#6466)

This commit is contained in:
Andrew Harvard
2026-01-13 10:06:51 -05:00
committed by GitHub
parent 5c506a8158
commit f3157087e0
@@ -110,19 +110,9 @@ export function SessionInsights() {
};
const formatTokens = (tokens: number | undefined): string => {
if (!tokens) {
return '0';
}
if (tokens >= 1_000_000_000) {
return `${(tokens / 1_000_000_000).toFixed(2)}B`;
}
if (tokens >= 1_000_000) {
return `${(tokens / 1_000_000).toFixed(2)}M`;
}
if (tokens >= 1_000) {
return `${(tokens / 1_000).toFixed(1)}K`;
}
return tokens.toString();
return new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 2 }).format(
tokens || 0
);
};
// Render skeleton loader while data is loading