Unable to add decimal in input type even after adding step

40 Views Asked by At

I have HTML input which is set to be a numeric input including the up and down carets. To my surprise I am unable to enter any decimal numbers.

<input type="number" />

It does not accept such input and jumps back to a non-decimal number. Is there any way I can keep the input type numeric and still allow decimal numbers?

2

There are 2 best solutions below

0
jeremy-denis On

you can use step attribute to say the number input allow decimal

<input type="number" min="0" max="10" step="0.1"/>

0
Bhavy Ladani On

If you want to allow any number of decimal then use this:

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

If you want specific like two decimal places then set like this:

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

Hope it helps!