import { CURRENCY_SHORT } from "./constants"; /** Format fictional credits: 10000 -> "10,000 SC". Never uses a currency sign. */ export function formatSC(amount: number | bigint | string, opts: { unit?: boolean } = {}): string { const n = typeof amount === "bigint" ? Number(amount) : typeof amount === "string" ? Number(amount) : amount; const s = Math.trunc(n).toLocaleString("en-US"); return opts.unit === false ? s : `${s} ${CURRENCY_SHORT}`; } /** Compact: 1250000 -> "1.25M" */ export function formatCompact(n: number): string { if (Math.abs(n) >= 1_000_000) return `${(n / 1_000_000).toFixed(2).replace(/\.?0+$/, "")}M`; if (Math.abs(n) >= 10_000) return `${(n / 1_000).toFixed(1).replace(/\.?0+$/, "")}K`; return Math.trunc(n).toLocaleString("en-US"); } export function formatMultiplier(m: number): string { if (m >= 100) return `${Math.round(m).toLocaleString("en-US")}×`; if (m >= 10) return `${m.toFixed(1).replace(/\.0$/, "")}×`; return `${m.toFixed(2).replace(/\.?0+$/, "")}×`; } export function formatPercent(p: number, digits = 2): string { return `${(p * 100).toFixed(digits)}%`; }