Skip to content

Commit 897dcdf

Browse files
rajbosCopilot
andcommitted
Reduce cost display precision to 2 decimal places
formatCost now uses 2 decimal places (was 4) everywhere: webview details panel, status-bar tooltip, and the related test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 583908a commit 897dcdf

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

vscode-extension/src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,8 @@ class CopilotTokenTracker implements vscode.Disposable {
13321332
tooltip.appendMarkdown(`📅 Today \n`);
13331333
tooltip.appendMarkdown(`| | |\n|-----------------------|-------|\n`);
13341334
tooltip.appendMarkdown(`| Tokens : | ${detailedStats.today.tokens.toLocaleString()} |\n`);
1335-
tooltip.appendMarkdown(`| Estimated cost (est.) : | $ ${detailedStats.today.estimatedCost.toFixed(4)} |\n`);
1336-
tooltip.appendMarkdown(`| Estimated cost (TBB) : | $ ${(detailedStats.today.estimatedCostCopilot ?? 0).toFixed(4)} |\n`);
1335+
tooltip.appendMarkdown(`| Estimated cost (est.) : | $ ${detailedStats.today.estimatedCost.toFixed(2)} |\n`);
1336+
tooltip.appendMarkdown(`| Estimated cost (TBB) : | $ ${(detailedStats.today.estimatedCostCopilot ?? 0).toFixed(2)} |\n`);
13371337
tooltip.appendMarkdown(`| CO₂ estimated : | ${detailedStats.today.co2.toFixed(2)} grams |\n`);
13381338
tooltip.appendMarkdown(`| Water estimated : | ${detailedStats.today.waterUsage.toFixed(3)} liters |\n`);
13391339
tooltip.appendMarkdown(`| Sessions : | ${detailedStats.today.sessions} |\n`);
@@ -1346,8 +1346,8 @@ class CopilotTokenTracker implements vscode.Disposable {
13461346
tooltip.appendMarkdown(`📊 Last 30 Days \n`);
13471347
tooltip.appendMarkdown(`| | |\n|-----------------------|-------|\n`);
13481348
tooltip.appendMarkdown(`| Tokens : | ${detailedStats.last30Days.tokens.toLocaleString()} |\n`);
1349-
tooltip.appendMarkdown(`| Estimated cost (est.) : | $ ${detailedStats.last30Days.estimatedCost.toFixed(4)} |\n`);
1350-
tooltip.appendMarkdown(`| Estimated cost (TBB) : | $ ${(detailedStats.last30Days.estimatedCostCopilot ?? 0).toFixed(4)} |\n`);
1349+
tooltip.appendMarkdown(`| Estimated cost (est.) : | $ ${detailedStats.last30Days.estimatedCost.toFixed(2)} |\n`);
1350+
tooltip.appendMarkdown(`| Estimated cost (TBB) : | $ ${(detailedStats.last30Days.estimatedCostCopilot ?? 0).toFixed(2)} |\n`);
13511351
tooltip.appendMarkdown(`| CO₂ estimated : | ${detailedStats.last30Days.co2.toFixed(2)} grams |\n`);
13521352
tooltip.appendMarkdown(`| Water estimated : | ${detailedStats.last30Days.waterUsage.toFixed(3)} liters |\n`);
13531353
tooltip.appendMarkdown(`| Sessions : | ${detailedStats.last30Days.sessions} |\n`);

vscode-extension/src/webview/shared/formatUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ export function formatCompact(value: number): string {
9292
}
9393

9494
/**
95-
* Formats a number as a USD cost with 4 decimal places.
95+
* Formats a number as a USD cost with 2 decimal places.
9696
*/
9797
export function formatCost(value: number): string {
9898
return new Intl.NumberFormat(currentLocale, {
9999
style: 'currency',
100100
currency: 'USD',
101-
minimumFractionDigits: 4,
102-
maximumFractionDigits: 4
101+
minimumFractionDigits: 2,
102+
maximumFractionDigits: 2
103103
}).format(value);
104104
}

vscode-extension/test/unit/webview-utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ test('formatNumber: adds thousand separators', () => {
8282

8383
// ── formatCost ──────────────────────────────────────────────────────────
8484

85-
test('formatCost: formats as USD with 4 decimal places', () => {
85+
test('formatCost: formats as USD with 2 decimal places', () => {
8686
setFormatLocale('en-US');
8787
const result = formatCost(1.23456789);
8888
assert.ok(result.includes('$'), 'should contain dollar sign');
89-
assert.ok(result.includes('1.2346'), 'should round to 4 decimal places');
89+
assert.ok(result.includes('1.23'), 'should round to 2 decimal places');
9090
});
9191

9292
test('formatCost: zero cost', () => {
9393
setFormatLocale('en-US');
9494
const result = formatCost(0);
9595
assert.ok(result.includes('$'), 'should contain dollar sign');
96-
assert.ok(result.includes('0.0000'), 'should show four decimal zeros');
96+
assert.ok(result.includes('0.00'), 'should show two decimal zeros');
9797
});

0 commit comments

Comments
 (0)