How to handle floats and decimal separators with html5 input type number

后端 未结 10 772
情话喂你
情话喂你 2020-11-27 11:15

Im building web app which is mainly for mobile browsers. Im using input fields with number type, so (most) mobile browsers invokes only number keyboard for better user exper

10条回答
  •  温柔的废话
    2020-11-27 11:47

    When you call $("#my_input").val(); it returns as string variable. So use parseFloat and parseIntfor converting. When you use parseFloat your desktop or phone ITSELF understands the meaning of variable.

    And plus you can convert a float to string by using toFixed which has an argument the count of digits as below:

    var i = 0.011;
    var ss = i.toFixed(2); //It returns 0.01
    

提交回复
热议问题