Format Number
<cs-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
Percentage
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 number is formatted correctly for the target locale.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.
import '@cruglobal/cornerstone-components/components/format-number/format-number.js';
import './cornerstone/components/format-number/format-number.js';
import CsFormatNumber from '@cruglobal/cornerstone-components/react/format-number/index.js';
Attributes & Properties
Learn more about attributes and properties.
| Property | Attribute | Description | Type | Default | Reflects |
|---|---|---|---|---|---|
currency | currency | The ISO 4217 currency code to use when formatting. | string | 'USD' | — |
currencyDisplay | currency-display | How to display the currency. | 'symbol' | 'narrowSymbol' | 'code' | 'name' | 'symbol' | — |
maximumFractionDigits | maximum-fraction-digits | The maximum number of fraction digits to use. Possible values are 0-100. | number | — | — |
maximumSignificantDigits | maximum-significant-digits | The maximum number of significant digits to use,. Possible values are 1-21. | number | — | — |
minimumFractionDigits | minimum-fraction-digits | The minimum number of fraction digits to use. Possible values are 0-100. | number | — | — |
minimumIntegerDigits | minimum-integer-digits | The minimum number of integer digits to use. Possible values are 1-21. | number | — | — |
minimumSignificantDigits | minimum-significant-digits | The minimum number of significant digits to use. Possible values are 1-21. | number | — | — |
type | type | The formatting style to use. | 'currency' | 'decimal' | 'percent' | 'decimal' | — |
value | value | The number to format. | number | 0 | — |
withoutGrouping | without-grouping | Turns off grouping separators. | boolean | false | — |

