Skip to content

Commit 4adf899

Browse files
a16iclaude
andcommitted
Fix StatCard crash: handle string values from Postgres counts
formatNum now safely parses string numbers instead of crashing on .toFixed() when Postgres returns count as string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5071a49 commit 4adf899

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

web/src/components/StatCard.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Sparkline } from "./Sparkline";
22

3-
function formatNum(n: number): string {
4-
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
5-
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
6-
return n.toString();
3+
function formatNum(n: number | string): string {
4+
const v = typeof n === "string" ? parseFloat(n) : n;
5+
if (isNaN(v)) return "0";
6+
if (v >= 1_000_000) return `${(v / 1_000_000).toFixed(1)}M`;
7+
if (v >= 1_000) return `${(v / 1_000).toFixed(1)}K`;
8+
return v.toString();
79
}
810

911
export function StatCard({

0 commit comments

Comments
 (0)