export function fmtUsd(value: number, compact = true): string { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", notation: compact && Math.abs(value) >= 10_000 ? "compact" : "standard", maximumFractionDigits: Math.abs(value) >= 10_000 ? 1 : 2, }).format(value); } export function fmtPct(value: number, digits = 2): string { return `${(value * 100).toFixed(digits)}%`; } export function fmtAprPct(value: number): string { const pct = value * 100; if (pct > 9_999) return ">9,999%"; if (pct >= 1_000) return `${Math.round(pct).toLocaleString("en-US")}%`; return `${pct.toFixed(1)}%`; } export function fmtNum(value: number): string { return new Intl.NumberFormat("en-US", { notation: Math.abs(value) >= 10_000 ? "compact" : "standard", maximumFractionDigits: 1, }).format(value); } export function fmtCountdown(untilSec: number): string { const s = Math.max(untilSec - Math.floor(Date.now() / 1000), 0); const d = Math.floor(s / 86_400); const h = Math.floor((s % 86_400) / 3_600); const m = Math.floor((s % 3_600) / 60); if (d > 0) return `${d}d ${h}h`; if (h > 0) return `${h}h ${m}m`; return `${m}m`; }