Format Number
<wa-format-number>
Formats a number for display using the specified locale and options, including currency, percent, and unit styles. Powered by the Intl.NumberFormat API.
Localization is handled by the browser's Intl.NumberFormat API. No language packs are required.
Examples
Percentages
To get the value as a percent, set the type attribute to percent.
Localization
Use the lang attribute to set the number formatting locale.
German:
Russian:
Currency
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 lang to ensure the the number is formatted correctly for the target locale.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/format-number/format-number.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/format-number/format-number.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/format-number/format-number.js';
To import this component for React 18 or below, use the following code:
import WaFormatNumber from '@awesome.me/webawesome/dist/react/format-number/index.js';
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefined |
||
currencycurrency |
The ISO 4217 currency code to use when formatting.
Type
stringDefault
'USD' |
||
currencyDisplaycurrency-display |
How to display the currency.
Type
'symbol' | 'narrowSymbol' | 'code' | 'name'Default
'symbol' |
||
maximumFractionDigitsmaximum-fraction-digits |
The maximum number of fraction digits to use. Possible values are 0-100.
Type
number |
||
maximumSignificantDigitsmaximum-significant-digits |
The maximum number of significant digits to use,. Possible values are 1-21.
Type
number |
||
minimumFractionDigitsminimum-fraction-digits |
The minimum number of fraction digits to use. Possible values are 0-100.
Type
number |
||
minimumIntegerDigitsminimum-integer-digits |
The minimum number of integer digits to use. Possible values are 1-21.
Type
number |
||
minimumSignificantDigitsminimum-significant-digits |
The minimum number of significant digits to use. Possible values are 1-21.
Type
number |
||
typetype |
The formatting style to use.
Type
'currency' | 'decimal' | 'percent'Default
'decimal' |
||
valuevalue |
The number to format.
Type
numberDefault
0 |
||
withoutGroupingwithout-grouping |
Turns off grouping separators.
Type
booleanDefault
false |