Make an html number input always display 2 decimal places

后端 未结 8 509
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 05:09

I\'m making a form where the user can enter a dollar amount using an html number input tag. Is there a way to have the input box always display 2 decimal places?

8条回答
  •  渐次进展
    2020-11-30 06:06

    An even simpler solution would be this (IF you are targeting ALL number inputs in a particular form):

    //limit number input decimal places to two
    $(':input[type="number"]').change(function(){
         this.value = parseFloat(this.value).toFixed(2);
    });
    

提交回复
热议问题