From a34ace5bd34121db06346feb8a67fc28140222be Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 5 Jan 2026 17:57:02 +0530 Subject: [PATCH] formatNumberWithCommas --- .../pricing_calculator/cost_results.tsx | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/ui/litellm-dashboard/src/components/CostTrackingSettings/pricing_calculator/cost_results.tsx b/ui/litellm-dashboard/src/components/CostTrackingSettings/pricing_calculator/cost_results.tsx index 8e81cd2df4b..3abdba106c1 100644 --- a/ui/litellm-dashboard/src/components/CostTrackingSettings/pricing_calculator/cost_results.tsx +++ b/ui/litellm-dashboard/src/components/CostTrackingSettings/pricing_calculator/cost_results.tsx @@ -3,21 +3,24 @@ import { Text } from "@tremor/react"; import { Card, Statistic, Row, Col, Divider, Spin } from "antd"; import { DollarOutlined, LoadingOutlined } from "@ant-design/icons"; import { CostEstimateResponse } from "../types"; +import { formatNumberWithCommas } from "@/utils/dataUtils"; interface CostResultsProps { result: CostEstimateResponse | null; loading: boolean; } -const formatCurrency = (value: number | null | undefined): string => { +const formatCost = (value: number | null | undefined): string => { if (value === null || value === undefined) return "-"; - if (value < 0.01) return `$${value.toFixed(6)}`; - return `$${value.toFixed(4)}`; + if (value === 0) return "$0"; + if (value < 0.0001) return `$${value.toExponential(2)}`; + if (value < 1) return `$${value.toFixed(4)}`; + return `$${formatNumberWithCommas(value, 2, true)}`; }; -const formatLargeCurrency = (value: number | null | undefined): string => { +const formatRequests = (value: number | null | undefined): string => { if (value === null || value === undefined) return "-"; - return `$${value.toFixed(2)}`; + return formatNumberWithCommas(value, 0, true); }; const CostResults: React.FC = ({ result, loading }) => { @@ -61,7 +64,7 @@ const CostResults: React.FC = ({ result, loading }) => { } /> @@ -69,21 +72,21 @@ const CostResults: React.FC = ({ result, loading }) => { 0 ? "#faad14" : undefined, @@ -96,13 +99,13 @@ const CostResults: React.FC = ({ result, loading }) => { {result.daily_cost !== null && ( } /> @@ -110,21 +113,21 @@ const CostResults: React.FC = ({ result, loading }) => { 0 ? "#faad14" : undefined, @@ -138,13 +141,13 @@ const CostResults: React.FC = ({ result, loading }) => { {result.monthly_cost !== null && ( } /> @@ -152,21 +155,21 @@ const CostResults: React.FC = ({ result, loading }) => { 0 ? "#faad14" : undefined, @@ -181,11 +184,11 @@ const CostResults: React.FC = ({ result, loading }) => {
Token Pricing: {result.input_cost_per_token && ( - Input: ${(result.input_cost_per_token * 1000000).toFixed(2)}/1M tokens + Input: ${formatNumberWithCommas(result.input_cost_per_token * 1_000_000, 2)}/1M tokens )} {result.input_cost_per_token && result.output_cost_per_token && " | "} {result.output_cost_per_token && ( - Output: ${(result.output_cost_per_token * 1000000).toFixed(2)}/1M tokens + Output: ${formatNumberWithCommas(result.output_cost_per_token * 1_000_000, 2)}/1M tokens )}
)} @@ -194,4 +197,3 @@ const CostResults: React.FC = ({ result, loading }) => { }; export default CostResults; -