Format locale-aware number strings
How locale-aware number formatting changes separators, digits and spacing, when the result is safe to copy or share, and when plain numbers work better.
Locale-aware number formatting turns a raw value such as 1234567.89 into a string a reader in a given region expects, such as 1,234,567.89 for US English or 1.234.567,89 for German. This review covers what that transformation changes, where the result works well, and where a plain, unformatted number is the better choice. It describes documented behavior and general principles. No specific tool was tested, and the gaps are flagged where they apply.
Is locale formatting suitable for your use?
Recommendation: use locale-formatted strings for display to people, and keep raw numbers for storage, calculation and data exchange. The main benefit is readability. Readers see the separators and digit grouping they already know, which reduces misreading of large values and decimals. The main tradeoff is that the output is presentation text, not data. It can be ambiguous across locales, it is hard to parse back reliably, and it may contain characters that other software does not expect.
Plain, canonical numbers (digits, an optional minus sign, and a period as the decimal mark, with no grouping) are preferable in these cases:
- CSV, JSON, API payloads, configuration files and database fields
- Values another program will read, sort or calculate with
- Content shared with an audience whose locale you do not know
- Identifiers that look numeric but are not quantities, such as ZIP codes, account numbers or years, which should not receive grouping separators
- Any place where rounding or truncation would change the meaning
What the transformation actually changes
Unlike CSS styling or bidirectional display, which only change how existing characters look, locale formatting produces a new string with different characters. The numeric value is not stored anywhere in the output. Only its written form is. The terms reverse, mirror and font do not describe this process. Nothing is reversed or mirrored, and no glyphs are substituted for style. The changes fall into a few categories:
- Decimal separator: a period in some locales, a comma in others
- Grouping separator: a comma, period, space, apostrophe or another character, depending on the locale
- Grouping pattern: most locales group by thousands, but Indian English groups as 12,34,567 after the first three digits
- Digits: some locales use non-Latin digit sets, such as Arabic-Indic digits in some Arabic locales
- Spacing characters: some locales use a non-breaking space or a narrow non-breaking space instead of an ordinary space
- Rounding: formatters apply default fraction-digit limits unless told otherwise, so the displayed value can differ from the stored value
- Invisible marks: some locale data inserts directional formatting characters so the number displays correctly next to right-to-left text
Typical outputs for the same value are shown below. The exact characters come from the locale data (commonly the Unicode CLDR) bundled with the runtime or operating system. They can differ between versions, so treat these as illustrative rather than guaranteed.
| Locale | Typical output for 1234567.891 | Notes |
| en-US | 1,234,567.891 | Comma grouping, period decimal |
| de-DE | 1.234.567,891 | Period grouping, comma decimal |
| fr-FR | 1 234 567,891 | Grouping character is usually a narrow non-breaking space, not an ordinary space |
| en-IN | 12,34,567.891 | Lakh/crore grouping pattern |
| ar-EG | ١٬٢٣٤٬٥٦٧٫٨٩١ | Arabic-Indic digits with Arabic separators in many runtime versions |
In JavaScript, the standard interfaces are Number.prototype.toLocaleString and Intl.NumberFormat. Calling toLocaleString without a locale argument uses the runtime's default locale, so the same code can produce different strings on different machines or for different users. Passing an explicit locale makes the output predictable.
const n = 1234567.891;
// Explicit locales give predictable output
new Intl.NumberFormat('en-US').format(n); // "1,234,567.891"
new Intl.NumberFormat('de-DE').format(n); // "1.234.567,891"
// Default fraction limit for decimal style is 3 digits, so this rounds
new Intl.NumberFormat('en-US').format(1234.5678); // "1,234.568"
// No locale argument: depends on the runtime's default locale
n.toLocaleString();
// Inspect the actual separator characters instead of guessing
new Intl.NumberFormat('fr-FR').formatToParts(n)
.filter(p => p.type === 'group')
.map(p => p.value.codePointAt(0).toString(16)); // e.g. ["202f", "202f"]
The rounding line matters for suitability. If precision is important, set the fraction-digit options explicitly. Otherwise the formatted string can show a value that differs from the source.
Will the result stay readable and usable after copying or sharing?
For a person reading a display in their own locale, yes. Problems appear when the string leaves that context.
- Ambiguity across locales: 1.234 means about one and a quarter in US English and one thousand two hundred thirty-four in German. Once copied, the string does not record which locale produced it.
- Parsing: JavaScript's Intl has no standard parsing counterpart to NumberFormat. Functions such as Number() or parseFloat() do not understand locale separators, so Number("1,234") returns NaN and parseFloat("1,234") returns 1.
- Hidden characters: narrow non-breaking spaces, non-breaking spaces and directional marks look like ordinary spacing or nothing at all. They can break string comparisons, naive find-and-replace, and validation that expects ASCII.
- Search: a search for 1234567 will not match the text 1,234,567 unless the search system normalizes numbers. Search behavior depends on the specific system, and no particular engine was tested here.
- Spreadsheets and other apps: whether a pasted string is treated as a number or as text depends on the destination's locale settings. A value formatted for one locale may arrive as text in another. Check the specific application rather than assuming.
- Editing: users who edit a formatted value in a form field may introduce mixed separators, which the receiving code must then handle.
Accessibility: correctly formatted numbers in the reader's locale are generally the most readable choice for sighted users. How a particular screen reader announces grouping separators, non-Latin digits or invisible directional marks depends on the screen reader, its speech settings and the declared page language. No documentation or scoped test for a named assistive technology was available for this review, so no specific claims are made. Declaring the content language (for example, with the lang attribute in HTML) gives assistive technology the information it needs to choose pronunciation rules. Testing with the actual screen readers your audience uses is the reliable way to confirm behavior.
When to provide a plain-text equivalent
Provide or retain an unformatted value alongside the display string in these situations:
- Readers may copy the number into another tool
- The number is downloadable or exported
- The page mixes locales or the reader's locale is unknown
- The exact value matters and the display is rounded
In HTML, the data element or a data attribute can carry the machine-readable value while the visible text stays localized. In exports, write canonical numbers and leave formatting to the application that opens the file.
Bottom line
Locale-aware formatting preserves meaning only for a reader who knows which locale is in use, and only when rounding is controlled. Use it at the display layer with an explicit locale and explicit precision. Inspect the output with formatToParts when hidden characters matter. Keep the raw number wherever text will be copied, parsed, searched or exchanged between systems.