Locale
The locale option detects the thousand and decimal separators, and the digit-grouping style, through Intl.NumberFormat. An explicit groupingStyle overrides the detected one.
de-CH- Thousand separator
- apostrophe
- Decimal separator
- full stop
- Grouping
- 3-3-3
- Field shows
- ""
- Value you get
- "1234567.89"
- Thousand separator
- . U+002E full stop
- Decimal separator
- , U+002C comma
- Grouping
- thousand (3-3-3)
The playground above is built with numora-react. A vanilla NumoraInput with the same options shows the same text.
Where the separators come from
By default the field uses , for thousands and . for decimals. Numora does not read the browser's locale unless you ask it to. There are two ways to change the separators.
Pass them yourself with thousandSeparator and decimalSeparator. Or set locale and Numora derives them. locale: 'de-DE' uses that locale and locale: true uses the browser's.
You can mix the two. A separator you pass wins, and locale fills in the ones you did not set.
Each separator is exactly one character. It cannot be a digit or one of - + e E k K m M b B t T, which Numora reads as a sign, an exponent or a compact-notation suffix. The two separators must be different. Numora throws on an invalid separator.
A separator you pass never clashes with one you did not. If it is the character the defaults or the locale would use for the other separator, the other one switches: thousandSeparator: '.' on its own gives a , decimal, and decimalSeparator: ',' on its own gives a . thousand separator. Numora only throws when you pass the same character for both.
The separators only change what the field shows. The value you get back has the same format in every locale. See Value types.
Browser locale
locale: true reads both separators from the browser's locale. A separator you pass still wins.
Specific locale tag
Pass a BCP 47 tag to pin the separators to one locale. locale: true reads the locale of whatever runtime the code runs in. On a server that is the server's locale and not the visitor's, so pass the tag there.
Grouping style detection
Indic locales group digits 3-2-2 (lakh and crore), not 3-3-3. Leave groupingStyle unset and Numora takes it from the locale, so hi-IN and en-IN get 'lakh'.
Numora can only detect 'thousand' and 'lakh'. Intl.NumberFormat reports 3-3-3 grouping for zh-CN and ja-JP, so 4-4-4 grouping never comes from a locale. Pass groupingStyle: 'wan' yourself.
getSeparatorsFromLocale
getSeparatorsFromLocale returns the separators and grouping style for a tag, so you can read them or pass them in yourself.
To set the decimal separator without a locale, see Decimals.
Typing and pasting under a locale
A typed . and a typed , are both the decimal key in every locale, even when one of them is the field's thousand separator. In a de-DE field, typing 1234.5 shows 1.234,5. A native decimal mark such as the Arabic ٫ is a decimal key too.
Pasted text is read by its own format, not the field's. Paste 1,234,567.89 into a de-DE field and it shows 1.234.567,89. The raw value is 1234567.89. See Decimals for the rule on a single mark.
What the field displays
The field shows the locale's separators with ASCII digits and an ASCII -. In ar-EG it shows 1٬234٫5, not the Arabic-Indic ١٬٢٣٤٫٥ that Intl.NumberFormat prints, and in sv-SE it shows -, not − (U+2212). Numora still accepts typed and pasted native digits and minus signs and converts them to ASCII. With thousand grouping, Numora groups four-digit numbers too, so es-ES shows 1.234 where Intl prints 1234.
Changing the locale later
Call instance.update({ locale: 'fr-FR' }) on a live field. Numora keeps the raw value and rewrites the display with the new separators. An invalid tag throws and changes nothing. locale: false turns the locale off, and the field goes back to the thousandSeparator and decimalSeparator options.
Value format under a locale
defaultValue and setValue take the canonical raw value in every locale: ASCII digits, . as the decimal mark, no grouping. Under locale: 'de-DE', setValue('1234.5') displays "1.234,5", and instance.rawValue returns "1234.5". See Value types.