<cs-format-number>
StableHelpersSince 0.1

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.

English:
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.

npm Self-Hosted React
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.

PropertyAttributeDescriptionTypeDefaultReflects
currencycurrencyThe ISO 4217 currency code to use when formatting.string'USD'
currencyDisplaycurrency-displayHow to display the currency.'symbol' | 'narrowSymbol' | 'code' | 'name''symbol'
maximumFractionDigitsmaximum-fraction-digitsThe maximum number of fraction digits to use. Possible values are 0-100.number
maximumSignificantDigitsmaximum-significant-digitsThe maximum number of significant digits to use,. Possible values are 1-21.number
minimumFractionDigitsminimum-fraction-digitsThe minimum number of fraction digits to use. Possible values are 0-100.number
minimumIntegerDigitsminimum-integer-digitsThe minimum number of integer digits to use. Possible values are 1-21.number
minimumSignificantDigitsminimum-significant-digitsThe minimum number of significant digits to use. Possible values are 1-21.number
typetypeThe formatting style to use.'currency' | 'decimal' | 'percent''decimal'
valuevalueThe number to format.number0
withoutGroupingwithout-groupingTurns off grouping separators.booleanfalse