I have seen that some browsers localize the input type="number"
notation of numbers.
So now, in fields where my application displays longitude and latitude coordinates, I get stuff like "51,983" where it should be "51.982559". My workaround is to use input type="text"
instead, but I'd like to use the number input with correct display of decimals.
Is there a way to force browsers to use a decimal point in the number input, regardless of client-side local settings?
(It goes without saying that in my application I anyway correct this on the server side, but in my setup I also need it to be correct on the client side (because of some JavaScript)).
Thanks in advance.
UPDATE
As of right now, checking in Chrome Version 28.0.1500.71 m on Windows 7, the number input just does not accept decimals formatted with a comma. Proposed suggestions with the step
attribute do not seem to work.
According to the spec, You can use
any
as the value ofstep
attribute:As far as I understand it, the HTML5
input type="number
always returnsinput.value
as astring
.Apparently,
input.valueAsNumber
returns the current value as a floating point number. You could use this to return a value you want.See http://diveintohtml5.info/forms.html#type-number
1) 51,983 is a string type number does not accept comma
so u should set it as text
replace , with .
and change type attribute to number
Check out http://jsfiddle.net/ydf3kxgu/
Hope this solves your Problem
Use lang attribut on the input. Locale on my web app fr_FR, lang="en_EN" on the input number and i can use indifferently a comma or a dot. Firefox always display a dot, Chrome display a comma. But both separtor are valid.
With the step attribute specified to the precision of the decimals you want, your html5 numeric input will accept decimals. eg. to take values like 10.56; i mean 2 decimal place numbers, do this:
You can further specify the max attribute for the maximum allowable value.
Edit Add a lang attribute to the input element with a locale value that formats decimals with point instead of comma
one option is
javascript parseFloat()
... never do parse a "text chain" --> 12.3456
with point to a int...123456
(int remove the point) parse a text chain to a FLOAT...to send this coords to a server do this sending a text chain.
HTTP
only sendsTEXT
in the client keep out of parsing the input coords with "
int
", work with text stringsif you print the cords in the html with php or similar... float to text and print in html