Force decimal point instead of comma in HTML5 number input (client-side)

后端 未结 15 723
情话喂你
情话喂你 2020-11-29 03:05

I have seen that some browsers localize the input type=\"number\" notation of numbers.

So now, in fields where my application displays longitude and la

15条回答
  •  情歌与酒
    2020-11-29 03:58

    I found a blog article which seems to explain something related:
    HTML5 input type=number and decimals/floats in Chrome

    In summary:

    • the step helps to define the domain of valid values
    • the default step is 1
    • thus the default domain is integers (between min and max, inclusive, if given)

    I would assume that's conflating with the ambiguity of using a comma as a thousand separator vs a comma as a decimal point, and your 51,983 is actually a strangely-parsed fifty-one thousand, nine hundred and eight-three.

    Apparently you can use step="any" to widen the domain to all rational numbers in range, however I've not tried it myself. For latitude and longitude I've successfully used:

    
    
    

    It might not be pretty, but it works.

提交回复
热议问题