| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- export type CurrencyCode =
- | 'AUD'
- | 'BRL'
- | 'CAD'
- | 'CHF'
- | 'CLP'
- | 'COP'
- | 'DKK'
- | 'EUR'
- | 'GBP'
- | 'INR'
- | 'MXN'
- | 'NOK'
- | 'NZD'
- | 'PEN'
- | 'SEK'
- | 'SGD'
- | 'USD'
- export function formatCurrencyLocalized(
- amount: number,
- currency: CurrencyCode,
- locale: string,
- stripIfInteger = false
- ): string {
- const options: Intl.NumberFormatOptions = { style: 'currency', currency }
- if (stripIfInteger && Number.isInteger(amount)) {
- options.minimumFractionDigits = 0
- }
- try {
- return amount.toLocaleString(locale, {
- ...options,
- currencyDisplay: 'narrowSymbol',
- })
- } catch {}
- try {
- return amount.toLocaleString(locale, options)
- } catch {}
- return `${currency} ${amount}`
- }
|