/** * Formats money amount with appropriate currency symbol * Uses browser's Intl.NumberFormat for consistent currency formatting */ export function formatMoney(amount: string, currencyCode: string): string { try { // Use en-US specifically for USD to get $ instead of US$ // For other currencies, use browser locale but fallback to en-US const locale = currencyCode === 'USD' ? 'en-US' : navigator.language || 'en-US' return new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode, }).format(Number(amount)) } catch (error) { // Fallback if currency code is invalid or not supported console.warn(`Invalid currency code: ${currencyCode}`, error) return `${currencyCode} ${amount}` } }