| 33 | |
| 34 | export const formatCurrency = |
| 35 | (locale: string) => |
| 36 | ( |
| 37 | amount: number, |
| 38 | options?: { |
| 39 | currency?: string; |
| 40 | short?: boolean; |
| 41 | }, |
| 42 | ) => { |
| 43 | const short = options?.short ?? false; |
| 44 | const currency = options?.currency ?? 'USD'; |
| 45 | if (short) { |
| 46 | // Use compact notation for short format (e.g., "73K $") |
| 47 | const formatter = new Intl.NumberFormat(locale, { |
| 48 | notation: 'compact', |
| 49 | minimumFractionDigits: 0, |
| 50 | maximumFractionDigits: 1, |
| 51 | }); |
| 52 | const formatted = formatter.format(amount); |
| 53 | // Get currency symbol |
| 54 | const currencyFormatter = new Intl.NumberFormat(locale, { |
| 55 | style: 'currency', |
| 56 | currency: currency, |
| 57 | minimumFractionDigits: 0, |
| 58 | maximumFractionDigits: 0, |
| 59 | }); |
| 60 | const parts = currencyFormatter.formatToParts(0); |
| 61 | const symbol = |
| 62 | parts.find((part) => part.type === 'currency')?.value || '$'; |
| 63 | return `${formatted} ${symbol}`; |
| 64 | } |
| 65 | return new Intl.NumberFormat(locale, { |
| 66 | style: 'currency', |
| 67 | currency: currency, |
| 68 | minimumFractionDigits: 0, |
| 69 | maximumFractionDigits: 1, |
| 70 | }).format(amount); |
| 71 | }; |
| 72 | |
| 73 | export function useNumber() { |
| 74 | const locale = 'en-US'; |