Decimal in field number (html).

1

How to put decimal (1.0 and 1.10) in step="0.010" of a field type = number? I have already tried to do but always the zeros are left out, it is not possible to make a 1.60 height eg result is always 1.6.

    
asked by anonymous 07.11.2017 / 23:16

1 answer

1
The listeners are just for example, you do not need to use them. The code inside them demonstrates how to add a 0 to the right of the decimals):

document.getElementById("input").addEventListener("change", function(){
   this.value = parseFloat(this.value).toFixed(2);
});

document.getElementById("input").addEventListener("change", function(){
   this.value = parseFloat(this.value).toFixed(2);
});
<input id="input" type="number" step="0.010" />

Or with jQuery:

$("input").on("change",function(){
   $(this).val(parseFloat($(this).val()).toFixed(2));
});

$("input").on("change",function(){
   $(this).val(parseFloat($(this).val()).toFixed(2));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="input" type="number" step="0.010" />
    
07.11.2017 / 23:33