Tintin81
Tintin81

Reputation: 10215

What determines if input values are output with a dot or a comma?

In my web application I have input fields like these

<input type="number" value="50.0">

In the (German language) version of my browsers (Safari + Firefox + Chrome) this is output to the user as

50,0

This is kind of correct and useful since it is the standard notation of numbers in Germany (alongside most other countries in continental Europe).

My question is:

Will the same code be output as

50.0

to users who have their system language set to English?

And if so, is this some sort of standard that works across all (or most) browsers?

Thanks for any help.

Upvotes: 3

Views: 114

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201798

All that we can really say, apart from listing down results from experimentation with individual browsers in specific context, is that the format is implementation-dependent. Not even implementation-defined; browsers need not document how they deal with this.

HTML5 PR says explicitly but very vaguely:

This specification does not define what user interface user agents are to use; user agent vendors are encouraged to consider what would best serve their users' needs. For example, a user agent in Persian or Arabic markets might support Persian and Arabic numeric input (converting it to the format required for submission as described above). Similarly, a user agent designed for Romans might display the value in Roman numerals rather than in decimal; or (more realistically) a user agent designed for the French market might display the value with apostrophes between thousands and commas before the decimals, and allow the user to enter a value in that manner, internally converting it to the submission format described above.

The non-normative implementation notes make the situation even more vague:

Browsers are encouraged to use user interfaces that present dates, times, and numbers according to the conventions of either the locale implied by the input element's language or the user's preferred locale. Using the page's locale will ensure consistency with page-provided data.

In reality, it seems that no browser actually uses the page locale (as defined by a lang attribute). Instead, they use the browser locale, or the system locale (which need not be the same).

The bottom line is that HTML5 input elements have not been localized properly, and the spec does not even tell how they should be localized. If you need control over the locale, e.g. want to have the page locale used, you need to refrain from using <input type="number" ...> and use suitable library routines instead

Upvotes: 1

mplungjan
mplungjan

Reputation: 178350

It is dependent on your Decimal symbol setting, although in Chrome I seem to be able to type a dot as decimal point too:

Windows

Windows 7

OSX

OSX Maverics OSX Maverics

Upvotes: 1

Related Questions