def fmt_large(value) -> str: """Format a number in billions/millions with suffix.""" try: v = float(value) except (TypeError, ValueError): return "N/A" if abs(v) >= 1e12: return f"${v / 1e12:.2f}T" if abs(v) >= 1e9: return f"${v / 1e9:.2f}B" if abs(v) >= 1e6: return f"${v / 1e6:.2f}M" return f"${v:,.0f}" def fmt_currency(value) -> str: """Format a dollar amount with commas.""" try: return f"${float(value):,.2f}" except (TypeError, ValueError): return "N/A" def fmt_pct(value, decimals: int = 2) -> str: """Format a ratio as a percentage (0.12 → 12.00%).""" try: return f"{float(value) * 100:.{decimals}f}%" except (TypeError, ValueError): return "N/A" def fmt_ratio(value, decimals: int = 2) -> str: """Format a plain ratio/multiple (e.g. P/E).""" try: return f"{float(value):.{decimals}f}x" except (TypeError, ValueError): return "N/A" def fmt_number(value, decimals: int = 2) -> str: """Format a plain number.""" try: return f"{float(value):,.{decimals}f}" except (TypeError, ValueError): return "N/A" def delta_color(value) -> str: """Return 'normal', 'inverse' or 'off' for st.metric delta_color.""" try: return "normal" if float(value) >= 0 else "inverse" except (TypeError, ValueError): return "off"