Skip to content

Commit 1d5fbb7

Browse files
Analyze and remove usage cost rounding (#198)
<!-- CURSOR_SUMMARY --> --- > [!NOTE] > Standardizes currency display to exactly 2 decimals, shows vCPU/RAM with two-decimal precision in usage, and lowercases the add-on price label. > > - **Formatting Utilities**: > - `formatCurrency`: now enforces exactly 2 decimal places. > - `formatNumber`: adds `maxFractionDigits` parameter (default 0) for configurable precision. > - **Usage Display**: > - Shows `vcpu` and `ram` values with two decimal places in `formatHoveredValues` and `formatTotalValues`. > - **Billing UI**: > - Lowercases add-on price label text in `concurrent-sandboxes-addon-section.tsx`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 58b7f39. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 728a4f3 commit 1d5fbb7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/features/dashboard/billing/concurrent-sandboxes-addon-section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function ConcurrentSandboxAddonSection({
4949
<div className="flex flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
5050
<div className="flex-1">
5151
<p className="prose-body text-fg">+500 Concurrent Sandboxes</p>
52-
<p className="text-fg-tertiary prose-label mt-0.5 uppercase">
52+
<p className="text-fg-tertiary prose-label mt-0.5 lowercase">
5353
{`+${formatCurrency(priceCents / 100)}/mo`}
5454
</p>
5555
</div>

src/features/dashboard/usage/display-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ export function formatHoveredValues(
139139
timestamp: timestampLabel,
140140
},
141141
vcpu: {
142-
displayValue: formatNumber(vcpuHours),
142+
displayValue: formatNumber(vcpuHours, 'en-US', 2),
143143
label,
144144
timestamp: timestampLabel,
145145
},
146146
ram: {
147-
displayValue: formatNumber(ramGibHours),
147+
displayValue: formatNumber(ramGibHours, 'en-US', 2),
148148
label,
149149
timestamp: timestampLabel,
150150
},
@@ -177,12 +177,12 @@ export function formatTotalValues(totals: {
177177
timestamp: null,
178178
},
179179
vcpu: {
180-
displayValue: formatNumber(totals.vcpu),
180+
displayValue: formatNumber(totals.vcpu, 'en-US', 2),
181181
label: 'total over range',
182182
timestamp: null,
183183
},
184184
ram: {
185-
displayValue: formatNumber(totals.ram),
185+
displayValue: formatNumber(totals.ram, 'en-US', 2),
186186
label: 'total over range',
187187
timestamp: null,
188188
},

src/lib/utils/formatting.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,16 @@ export function formatAveragingPeriod(stepMs: number): string {
217217
* Format a number with locale-specific separators
218218
* @param value - Number to format
219219
* @param locale - Locale to use (defaults to 'en-US')
220+
* @param maxFractionDigits - Maximum decimal places to show (defaults to 0 for whole numbers)
220221
* @returns Formatted number string
221222
*/
222-
export function formatNumber(value: number, locale: string = 'en-US'): string {
223+
export function formatNumber(
224+
value: number,
225+
locale: string = 'en-US',
226+
maxFractionDigits: number = 0
227+
): string {
223228
return value.toLocaleString(locale, {
224-
maximumFractionDigits: 0,
229+
maximumFractionDigits: maxFractionDigits,
225230
})
226231
}
227232

@@ -421,6 +426,7 @@ export function combineDateTimeStrings(
421426

422427
/**
423428
* Format a currency amount with the specified currency and locale
429+
* Always displays exactly 2 decimal places with standard rounding
424430
* @param amount - Amount to format
425431
* @param currency - Currency to use (defaults to 'USD')
426432
* @param locale - Locale to use (defaults to 'en-US')
@@ -434,7 +440,7 @@ export function formatCurrency(
434440
return Intl.NumberFormat(locale, {
435441
style: 'currency',
436442
currency,
437-
minimumFractionDigits: 0,
443+
minimumFractionDigits: 2,
438444
maximumFractionDigits: 2,
439445
}).format(amount)
440446
}

0 commit comments

Comments
 (0)