Handlebar Helper Function: FormatCurrency
The formatCurrency helper function formats a number as a currency value.
This function is a convenience function that calls formatNumber with the currency format type. It throws an error if the input can't be converted to a number.
| Parameter | Type | Description |
|---|---|---|
number | number or string | Required. The number to format as a currency value. If the value is a string, it must be convertible to a number. |
cultureCode | string | A POSIX locale code for currency formatting, such as en_US or zh-TW. The operation supports both hyphen (fr-CA) and underscore (fr_CA) formats. If you don’t specify a culture code, the operation uses en_US. |
The operation returns a formatted string representation of the number as a currency value, using the specified locale’s currency format. Different locales use different currency symbols, decimal separators, and grouping patterns. For example, {{formatCurrency 1234.56 "en-US"}} returns $1,234.56, while {{formatCurrency 1234.56 "de-DE"}} returns 1.234,56 €. Different locales handle the rounding of currency values in different ways. For example, Japanese Yen is usually expressed without decimal places, so {{formatCurrency 1234.56 "ja-JP"}} returns ¥1,235.
If the input can’t be converted to a number, the operation throws an exception. This behavior helps you handle conversion errors gracefully by using the fallback helper, as shown in this example.
In this example, if orderTotal can’t be converted to a number, the operation returns Amount not available.