Skip to content

Commit f315708

Browse files
authored
Use Intl.NumberFormat for token formatting in SessionsInsights (#6466)
1 parent 5c506a8 commit f315708

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

ui/desktop/src/components/sessions/SessionsInsights.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,9 @@ export function SessionInsights() {
110110
};
111111

112112
const formatTokens = (tokens: number | undefined): string => {
113-
if (!tokens) {
114-
return '0';
115-
}
116-
if (tokens >= 1_000_000_000) {
117-
return `${(tokens / 1_000_000_000).toFixed(2)}B`;
118-
}
119-
if (tokens >= 1_000_000) {
120-
return `${(tokens / 1_000_000).toFixed(2)}M`;
121-
}
122-
if (tokens >= 1_000) {
123-
return `${(tokens / 1_000).toFixed(1)}K`;
124-
}
125-
return tokens.toString();
113+
return new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 2 }).format(
114+
tokens || 0
115+
);
126116
};
127117

128118
// Render skeleton loader while data is loading

0 commit comments

Comments
 (0)