(number: string | number | null | undefined, decimals = 0)
| 43 | * Format number with grouping |
| 44 | */ |
| 45 | export function formatNumber(number: string | number | null | undefined, decimals = 0): string { |
| 46 | if (number == null) return ''; |
| 47 | |
| 48 | const num = typeof number === 'string' ? parseFloat(number) : number; |
| 49 | if (isNaN(num)) return ''; |
| 50 | |
| 51 | return new Intl.NumberFormat('en-US', { |
| 52 | maximumFractionDigits: Math.min(Math.max(0, decimals), 20), |
| 53 | minimumFractionDigits: decimals, |
| 54 | useGrouping: true, |
| 55 | }).format(num); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Format price with currency |
no test coverage detected
searching dependent graphs…