javascript - parse float with two decimals, -


this input

<input type="text" name="price" class="solo-numeros"> 

with function

$(".solo-numeros").blur(function() {     var numb = parsefloat($(this).val().replace(/\d/g,"")).tofixed(2);     $(this).val(numb); }); 

i try change result input float 2 decimals

so try

555.61 

but on blur value change to

55561.00 

why that????

this happens because you're removing non-numeric characters (\d), such period. "55.61" becomes "5561", made two-decimal string-representation of float, hence "5561.00"

references:


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -