How can I make the HTML5 number field display trailing zeroes?

I attached an on(‘change’) event to the input you want to have trailing 0’s

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

It just takes the value, casts it to a float, renders it to a string to the number of decimal places, and puts it back in as the value.

Leave a Comment