From 1c0ece8f2ffcfc04885f0b5a97241c7882134dd6 Mon Sep 17 00:00:00 2001 From: Jer Miller Date: Wed, 15 Apr 2026 22:54:27 -0600 Subject: [PATCH] Fix token cost display: round to 2 decimal places instead of 6 Currency values on /app/tokens were showing excessive precision ($16.402396 instead of $16.40). Changed all cost rounding from 6 to 2 decimal places in both backend (routes.py) and frontend (formatCost). Rate values remain at 4 decimals as intended. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/tokens/routes.py | 20 ++++++++++---------- apps/tokens/workspace.html | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/tokens/routes.py b/apps/tokens/routes.py index ac41bce2e..2a9ccd131 100644 --- a/apps/tokens/routes.py +++ b/apps/tokens/routes.py @@ -187,9 +187,9 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: "output_tokens": data["output_tokens"], "cached_tokens": data["cached_tokens"], "reasoning_tokens": data["reasoning_tokens"], - "cost": round(data["cost"], 6), - "input_cost": round(data["input_cost"], 6), - "output_cost": round(data["output_cost"], 6), + "cost": round(data["cost"], 2), + "input_cost": round(data["input_cost"], 2), + "output_cost": round(data["output_cost"], 2), "models_used": sorted(list(data["models"])), "percent": round( (data["cost"] / total_cost * 100) if total_cost > 0 else 0, 1 @@ -205,9 +205,9 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: "provider": data["provider"], "requests": data["requests"], "tokens": data["tokens"], - "cost": round(data["cost"], 6), + "cost": round(data["cost"], 2), "avg_cost_per_request": round( - data["cost"] / data["requests"] if data["requests"] > 0 else 0, 6 + data["cost"] / data["requests"] if data["requests"] > 0 else 0, 2 ), "percent": round( (data["cost"] / total_cost * 100) if total_cost > 0 else 0, 1 @@ -222,7 +222,7 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: "context": ctx, "requests": data["requests"], "tokens": data["tokens"], - "cost": round(data["cost"], 6), + "cost": round(data["cost"], 2), "models_used": sorted(list(data["models"])), "percent": round( (data["cost"] / total_cost * 100) if total_cost > 0 else 0, 1 @@ -238,7 +238,7 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: "segment": seg, "requests": data["requests"], "tokens": data["tokens"], - "cost": round(data["cost"], 6), + "cost": round(data["cost"], 2), "models_used": sorted(list(data["models"])), "percent": round( (data["cost"] / total_cost * 100) if total_cost > 0 else 0, 1 @@ -285,14 +285,14 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: ttype["percent"] = round( (ttype["cost"] / total_cost * 100) if total_cost > 0 else 0, 1 ) - ttype["cost"] = round(ttype["cost"], 6) + ttype["cost"] = round(ttype["cost"], 2) return { "day": day, "total": { "requests": total_requests, "tokens": total_tokens, - "cost": round(total_cost, 6), + "cost": round(total_cost, 2), "segment_count": segment_count, "skipped_unknown": skipped_unknown, }, @@ -305,7 +305,7 @@ def _aggregate_token_data(day: str) -> Dict[str, Any]: t: { "requests": d["requests"], "tokens": d["tokens"], - "cost": round(d["cost"], 6), + "cost": round(d["cost"], 2), } for t, d in by_type.items() }, diff --git a/apps/tokens/workspace.html b/apps/tokens/workspace.html index 18ff66cda..72dcbb11e 100644 --- a/apps/tokens/workspace.html +++ b/apps/tokens/workspace.html @@ -548,7 +548,7 @@ const tableConfig = { // Format numbers function formatCost(value) { - return '$' + value.toFixed(6); + return '$' + value.toFixed(2); } function formatNumber(value) { -- 2.51.2