Skip to content

The only tool you need to know what is happening and how to fix it.

703 B
Raw Blame
export function formatCost(cost: number): string {
	if (cost === 0) return '$0';
	if (cost < 0.001) return `$${cost.toFixed(6)}`;
	if (cost < 0.01) return `$${cost.toFixed(4)}`;
	if (cost < 1) return `$${cost.toFixed(3)}`;
	return `$${cost.toFixed(2)}`;
}

export function formatCount(count: number): string {
	if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}m`;
	if (count >= 1_000) return `${(count / 1_000).toFixed(1)}k`;
	return count.toLocaleString();
}

export function formatTokens(tokens: number): string {
	if (tokens >= 1_000_000) return `${(tokens / 1_000_000).toFixed(1)}M`;
	if (tokens >= 1_000) return `${(tokens / 1_000).toFixed(1)}k`;
	return tokens.toLocaleString();
}