function formatCurrency(amount, locale, currency)
Formats a number as currency with specified locale and currency code
Name↑ | Type | Required | Description |
|---|---|---|---|
| amount | number | Required | The amount to format |
| currency | string | Optional | The currency code |
| locale | string | Optional | The locale to use for formatting |
function formatCurrency(amount, locale = 'en-US', currency = 'USD') {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency
}).format(amount);
}