Make an html number input always display 2 decimal places

后端 未结 8 528
伪装坚强ぢ
伪装坚强ぢ 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 05:49

    an inline solution combines Groot and Ivaylo suggestions in the format below:

    onchange="(function(el){el.value=parseFloat(el.value).toFixed(2);})(this)"
    

提交回复
热议问题