Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,15 @@ <h2>Model prices (per million tokens)</h2>
}

function formatCost(totalCost) {
const dollars = trimZeros(totalCost.toFixed(6));
if (totalCost >= 1) {
return `$${dollars}`;
} else {
const cents = trimZeros((totalCost * 100).toFixed(4));
return `$${dollars} (${cents} cents)`;
// Show whole dollar amounts without decimals (e.g. $60)
// and amounts with cents with two decimal places (e.g. $3.20, $0.05).
if (!isFinite(totalCost) || isNaN(totalCost)) return '$0';
const rounded = Math.round(totalCost);
// Treat values very close to integers as integers to avoid floating point noise
if (Math.abs(totalCost - rounded) < 1e-9) {
return `$${rounded}`;
}
return `$${totalCost.toFixed(2)}`;
}

function setPreset(modelKey) {
Expand Down