Of course, the value is a numbe...">

How to make display a semicolon with input type number?

I have this type of input type:

<input type="number"> 

Of course, the value is a number, how to make it display a semicolon? And make it compatible with most HTML 5 browsers?

I searched, but could not find a solution. I printed a number, but it does not display with a comma.

+3
source share
2 answers

You can use the French locale lang="fr" , which uses a comma for the decimal separator.

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Input test</title> <script> function init(){ document.getElementById('in1').value = 3.14; } </script> </head> <body onload="init()"> <input id="in1" lang="fr" type="number"> </body> </html> 

It works fine with Firefox 39.0:

enter image description here

but unfortunately it is not yet implemented in Chrome 44.

+1
source

You can use the step attribute to define decimal places, for example, if you want to show 1 decimal place that you can use:

 <input type="number" step="0.1"></input> 

Now, when you use the up and down arrows, it will increase and decrease the number by 0.1

-3
source

Source: https://habr.com/ru/post/1488488/


All Articles