What determines whether input values ​​are output with a period or comma?

In my web application I have input fields like this

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

      

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

50,0

      

This is correct and useful as it is the standard notation for numbers in Germany (along with most other continental European countries).

My question is:

Will the same code be output as

50.0

      

for users who have their system language set to English?

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

Thanks for any help.

+3


source to share


2 answers


It depends on your decimal point setting, although in Chrome I seem to be able to type point as a decimal point too:

Window

Windows 7



OSX

OSX MavericsOSX Maverics

+1


source


All we can really say, apart from listing the results of experiments with individual browsers in a specific context, is that the format is implementation dependent. Not even a definite implementation; the browser doesn't need to document how they handle this.

HTML5 PR says explicitly but very vaguely:

This specification does not define which custom user interface interfaces to use; user agent providers are encouraged to consider what is best to meet the needs of their users. For example, a user agent in Persian or Arabic markets might support Persian and Arabic numeric input (convert it to the format required for presentation, as described above). Likewise, a user agent designed for Romans can display the value in Roman numerals rather than decimal; or more realistic) a user agent targeted for the French market can display a value with apostrophes between thousands and commas to decimal places and allow the user to enter the value in this wayinternally converting it to the presentation format described above.

Non-normative implementation notes make the situation even more uncertain:



The browser is encouraged to use user interfaces that represent dates, times, and numbers according to conventions, either the locale implied by the language of the input elements or the user's preferred locale. Using the page locale will ensure consistency with the provided pages.

In reality, it seems that no browser actually uses the page's locale (as defined by the attribute lang

). Instead, they use the browser locale or the system locale (which don't have to be the same).

The bottom line is that HTML5 input elements weren't localized correctly, and the spec didn't even specify how they should be localized. If you need control over the locale eg. want to use the locale of the page, you need to refrain from using <input type="number" ...>

and instead use the appropriate library routines

+1


source







All Articles