Format Number

<wa-format-number> Stable Since 2.0

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

Link to This Section

Percentages

Link to This Section

To get the value as a percent, set the type attribute to percent.





Localization

Link to This Section

Use the lang attribute to set the number formatting locale.

English:
German:
Russian:

Currency

Link to This Section

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

Link to This Section

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.

CDN npm Self-Hosted React

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

Link to This Section

Learn more about attributes and properties.

Need a hand? Report a bug Ask for help
    No results