Decimal and Thousands Separators in HTML Number Inputs
How HTML number inputs handle commas, decimal points and thousands separators, why stored values differ from what users see, and when a text input is the better choice.
Developers often expect an HTML number input to accept a comma or show a thousands separator. It usually does neither reliably. The display can follow local conventions, but the value the field stores and submits stays in one fixed format. This review explains what changes between what a person types, what the browser shows and what the form sends, so you can decide whether the native input fits your use or whether you need a text field with your own formatting.
Short answer: is the native number input suitable?
Use the native number input for small quantities where people rarely type separators, such as item counts, ages or ratings. Its main benefit is built-in validation and a canonical value your code can trust. The decisive tradeoff is that you cannot control how the browser interprets a comma, and it will not display thousands separators. If users routinely enter large amounts, amounts in a locale that uses a comma as the decimal mark, or numbers they paste from spreadsheets, a plain text input with explicit parsing is usually the safer choice.
Plain text is also preferable for digit strings that are not quantities, such as postal codes, account numbers or card numbers. Several public-sector design systems advise against number inputs for these because stepping, rounding and stripping of leading zeros do not make sense for identifiers.
What the number input actually stores
The HTML specification requires the value of a number input to be a valid floating-point number: an optional minus sign, digits, an optional full stop followed by digits, and an optional exponent. There is no comma and no grouping separator in that format. Whatever a user sees on screen, the value property and the submitted form data use a full stop as the decimal mark.
If the field's contents cannot be read as a valid number, the value is sanitized to an empty string and valueAsNumber returns NaN. Your script therefore cannot recover what the user typed. A form can appear filled in yet submit nothing for that field.
Where the comma comes in: display and parsing
The specification lets browsers localize the user interface of a number input. Browsers may show and accept a comma as the decimal mark when the browser or page locale uses one, and the element's lang attribute may influence this. Implementations differ, and this article does not include browser-by-browser test results, so treat any particular behavior as something to verify in the browsers your audience uses.
This is the distinction to keep in mind: localization here is a presentation layer. A user may see 3,5 while the stored value is 3.5. The characters your code receives were converted by the browser, not by you, and you cannot reliably predict the conversion from the page alone.
Thousands separators are not supported
The native number input does not add grouping separators as the user types, and the canonical value format has no place for them. A typed or pasted grouping character either makes the entry invalid or is interpreted as a decimal mark, depending on the browser and locale. If readability of large numbers matters, such as amounts in the thousands or millions, you need a text input that formats the display while keeping a separate canonical value.
The step attribute and decimal input
A related trap has nothing to do with separators but is often blamed on them. The default step for a number input is 1, so a value like 2.5 fails validation unless you set step to a matching increment or to any. If decimals are rejected even when the separator looks correct, check the step attribute before you change locale handling.
<!-- Accepts decimals; value is always submitted with a full stop -->
<input type="number" name="weight" step="any" min="0">
<!-- Two decimal places, e.g. a price -->
<input type="number" name="price" step="0.01" min="0">
Locale conventions differ more than the comma-versus-period split
The JavaScript Intl.NumberFormat API shows how much formatting varies by locale. The outputs below come from current Unicode locale data as shipped in modern JavaScript engines. Exact characters can change between data versions, so check them in your target runtime.
const n = 1234567.5;
new Intl.NumberFormat('en-US').format(n); // "1,234,567.5"
new Intl.NumberFormat('de-DE').format(n); // "1.234.567,5"
new Intl.NumberFormat('fr-FR').format(n); // "1 234 567,5" (narrow no-break spaces)
new Intl.NumberFormat('en-IN').format(n); // "12,34,567.5" (lakh grouping)
Three points matter for text handling. The same character can be a decimal mark in one locale and a group separator in another. Some locales group digits in sizes other than threes. And French formatting uses a narrow no-break space rather than an ordinary space, so code that strips ordinary spaces, or a user who types a regular space, will not match the formatter's output.
The text-input alternative: format for display, store canonically
The common pattern is a text input with inputmode set to decimal, which asks mobile browsers for a numeric keyboard. Your code then converts between the displayed string and a canonical number. JavaScript has no built-in locale-aware number parser, but formatToParts reveals which characters a locale uses for grouping and decimals, and you can normalize input from that.
function separatorsFor(locale) {
const parts = new Intl.NumberFormat(locale).formatToParts(11111.1);
return {
group: parts.find(p => p.type === 'group')?.value ?? '',
decimal: parts.find(p => p.type === 'decimal')?.value ?? '.'
};
}
function parseLocalized(text, locale) {
const { group, decimal } = separatorsFor(locale);
let s = text.trim();
if (group) s = s.split(group).join('');
if (decimal !== '.') s = s.replace(decimal, '.');
if (!/^-?\d+(\.\d+)?$/.test(s)) return NaN;
return Number(s);
}
parseLocalized('1.234,5', 'de-DE'); // 1234.5
parseLocalized('1,234.5', 'en-US'); // 1234.5
This sketch shows the mechanism and is not production-ready. It does not handle the ordinary space a French-locale user might type in place of a narrow no-break space, currency symbols, other numbering systems, or signs other than a hyphen-minus. Test it against the inputs your users actually produce.
The ambiguity no parser can resolve
An entry like 1,234 means one thousand two hundred thirty-four under US conventions and roughly one and a quarter under German conventions. Without knowing which convention the person used, the string is ambiguous. Guessing from the browser locale works for most users and fails for people whose device locale differs from their habits, and for data pasted from elsewhere. If a misread would be costly, as with prices, dosages or transfer amounts, show the interpreted value back to the user, state the expected format next to the field, or both.
Copying, pasting and sharing
- Pasting into a native number input: grouped values like 1,234.56 may be rejected or misread depending on the browser and locale. The field may then hold an empty value with no visible error.
- Copying out of a formatted text field: the copied string carries the display separators, including invisible characters such as narrow no-break spaces. Spreadsheets or other systems set to a different locale may misread it.
- Sharing across regions: a formatted number is only unambiguous to readers who share its convention. For data exchange, such as APIs, exports and stored records, use the canonical full-stop format with no grouping, and apply locale formatting only at display time.
- Editing: if your script reformats a text field while the user types, the caret can jump and characters can appear unexpectedly. Formatting on blur, rather than on each keystroke, avoids most of this.
Accessibility considerations
Native number inputs are exposed to assistive technology as spin buttons, and arrow keys change the value by the step amount. That suits counts but can surprise users entering long amounts, and in some browsers scrolling over a focused field changes its value. A text input avoids the spin-button behavior. You then need to provide the expected format, error messages and the label association yourself.
This article does not include tests of how specific screen readers announce grouped or localized numbers, and announcement may depend on the screen reader, its language settings and the page's lang attribute. If your form handles critical amounts, test with the assistive technologies your users rely on rather than assuming a formatted display reads correctly. Clear visible instructions, such as an example of the accepted format, help everyone regardless of the result.
Comparing the approaches
| Approach | Comma as decimal mark | Thousands separators | Value your code receives | Best fit |
| Native number input | Browser-dependent, may follow locale | Not displayed; typed ones may invalidate entry | Canonical, or empty if invalid | Small counts and quantities |
| Text input with inputmode decimal and your own parsing | Under your control | Under your control, best applied on blur | Raw string you must normalize | Large amounts, mixed-locale audiences, pasted data |
| Plain text with a stated format and no formatting | Whatever you document | None | Raw string validated against one format | Identifiers and internal tools with a single convention |
Bottom line
The native number input preserves meaning well for simple quantities, because its stored value is always canonical, but it gives up control over how commas are interpreted and cannot show grouping. When readability of large numbers or predictable handling of commas matters, use a text input, format for display, and store the canonical number separately. Keep exported and shared data in the unformatted canonical form. Where an ambiguous entry could cause real harm, show users the value you interpreted before you accept it.