Make an html number input always display 2 decimal places

后端 未结 8 469
伪装坚强ぢ
伪装坚强ぢ 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);
    });
    
    0 讨论(0)
  • 2020-11-30 06:11

    You can use Telerik's numerictextbox for a lot of functionality

    <input id="account_rate" data-role="numerictextbox" data-format="#.000" data-min="0.001" data-max="100" data-decimals="3" data-spinners="false" data-bind="value: account_rate_value" onchange="APP.models.rates.buttons_state(true);" />
    

    the core code is free to download

    0 讨论(0)
提交回复
热议问题