Skip to content

Commit 4d45354

Browse files
Merge pull request #10517 from nshcr/feat-format-token-cost
feat(ui): format tokens and cost using locale-aware formatter
2 parents 8d22d58 + 00b4f8f commit 4d45354

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/desktop/src/components/codegen/CodegenSidebarEntry.svelte

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
}: Props = $props();
3737
3838
let isOpen = $state(false);
39+
40+
function formatNumber(n: number, fractionDigits = 0) {
41+
const options: Intl.NumberFormatOptions = {
42+
maximumFractionDigits: fractionDigits,
43+
minimumFractionDigits: fractionDigits
44+
};
45+
46+
// Use the user's locale (undefined) so thousands separator will match their locale.
47+
return new Intl.NumberFormat(undefined, options).format(n);
48+
}
3949
</script>
4050

4151
<div class="codegen-entry-wrapper" use:focusable={{ focusable: true, onAction: () => onclick?.() }}>
@@ -104,7 +114,7 @@
104114
<div class="entry-metadata text-12" in:fade={{ duration: 150 }}>
105115
<Tooltip text="Total tokens used and cost">
106116
<div class="flex gap-4 items-center">
107-
<p>{tokensUsed}</p>
117+
<p>{formatNumber(tokensUsed)}</p>
108118
<svg
109119
width="0.938rem"
110120
height="0.938rem"
@@ -125,7 +135,7 @@
125135
/>
126136
</svg>
127137
<div class="metadata-divider"></div>
128-
<p>${cost.toFixed(2)}</p>
138+
<p>${formatNumber(cost, 2)}</p>
129139
</div>
130140
</Tooltip>
131141

0 commit comments

Comments
 (0)