/** USD with no cents above $100, cents below. Signed variant for deltas. */
export function money(v: number): string {
  const abs = Math.abs(v)
  const digits = abs >= 100 ? 0 : abs >= 10 ? 1 : 2
  return `$${v.toLocaleString('en-US', { minimumFractionDigits: digits, maximumFractionDigits: digits })}`
}

export function signedMoney(v: number): string {
  if (Math.abs(v) < 0.5) return '±$0'
  return `${v > 0 ? '+' : '−'}${money(Math.abs(v))}`
}

/** Compact counts: 1234 → 1.2k, 1_200_000 → 1.2M */
export function compact(v: number): string {
  if (v >= 1_000_000) return `${(v / 1_000_000).toFixed(1)}M`
  if (v >= 1_000) return `${(v / 1_000).toFixed(v >= 10_000 ? 0 : 1)}k`
  return `${Math.round(v)}`
}
