Format Currency

3 parameters

2 of 6

function formatCurrency(amount, locale, currency)

Formats a number as currency with specified locale and currency code

Parameters

Name↑
Type
Required
Description
amountnumberRequiredThe amount to format
currencystringOptionalThe currency code
localestringOptionalThe locale to use for formatting

Function Implementation

function formatCurrency(amount, locale = 'en-US', currency = 'USD') {
  return new Intl.NumberFormat(locale, {
    style: 'currency',
    currency: currency
  }).format(amount);
}