formatCurrency()function
formatCurrency(amount: number, currency: string, options?: CurrencyFormatOptions, caller: AnyCaller = formatCurrency): string
| Param | Type | |
|---|---|---|
amount | number | Amount of money to format. required |
currency | string | ISO 4217 currency code, e.g. "USD" or "GBP". required |
options | CurrencyFormatOptions | Formatting options passed through to Intl.NumberFormat. |
caller | AnyCaller | Function to attribute a thrown error to (defaults to formatCurrency itself). Defaults to formatCurrency |
| Return | |
|---|---|
string | Locale-formatted currency string. |
| Throws | |
|---|---|
RequiredError | If currency is not a valid currency code. |
Format a currency amount (based on the user's browser language settings).
Examples
formatCurrency(1234.5, "USD") // "$1,234.50"