# Format Number (fw-format-number)
Format Number formats a number using the given locale and options.
Localization is handled by the Intl.NumberFormat
API
# Demo
Pass locale
attritube to set the formatting locale for the number.
English:
German:
Show Code
Pass type as percent
to get the value as percentage.
Show Code
To format a number as a monetary value, set the type attribute to currency
and set the currency attribute to the desired ISO 4217 currency code
.
You should also specify locale
attribute to ensure the the number is formatted correctly for the target locale.
USD:
GBP:
EUR:
CNY:
Show Code
# Usage
# Properties
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
currency | currency | The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as USD for the US dollar, EUR for the euro. If the style is "currency", the currency property must be provided. | string | undefined |
currencyDisplay | currency-display | Currency display formatting. | "code" \| "name" \| "narrowSymbol" \| "symbol" | 'symbol' |
currencySign | currency-sign | In many locales, accounting format means to wrap the number with parentheses instead of appending a minus sign. You can enable the above by setting the currencySign option to accounting . The default value is standard | "accounting" \| "standard" | 'standard' |
locale | locale | Locale used for formatting the number | string | undefined |
maximumFractionDigits | maximum-fraction-digits | The maximum number of fraction digits to use. Possible values are 0 - 20. | number | undefined |
maximumSignificantDigits | maximum-significant-digits | The maximum number of significant digits to use,. Possible values are 1 - 21. Default is 21 | number | 21 |
minimumFractionDigits | minimum-fraction-digits | The minimum number of fraction digits to use. Possible values are 0 - 20. | number | undefined |
minimumIntegerDigits | minimum-integer-digits | The minimum number of integer digits to use. Possible values are 1 - 21. Default is 1 | number | 1 |
minimumSignificantDigits | minimum-significant-digits | The minimum number of significant digits to use. Possible values are 1 - 21. Default is 1 | number | 1 |
type | type | Formatting style | "currency" \| "decimal" \| "percent" | 'decimal' |
useGrouping | use-grouping | Turns on/off grouping separators. | boolean | true |
value | value | Number to format. | number | 0 |
Built with ❤ at Freshworks