Make an html number input always display 2 decimal places

后端 未结 8 523
伪装坚强ぢ
伪装坚强ぢ 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:01

    What other folks posted here mainly worked, but using onchange doesn't work when I change the number using arrows in the same direction more than once. What did work was oninput. My code (mainly borrowing from MC9000):

    HTML

    
    

    JS

    function setTwoNumberDecimal(el) {
            el.value = parseFloat(el.value).toFixed(2);
        };
    

提交回复
热议问题