javascript - Multiplication of decimal values -


im experiencing weird problem. im trying multiply 2 decimal values, result integer/rounded number. if add decimals (for example tofixed(2), adds zeroes).

here script:

$(document).ready(function () {     $('.txtquantity, .txtrate').change(function () {       var txtquantity = $('.txtquantity').val();       var txtrate = $('.txtrate').val();       var total = parsefloat(txtquantity) * parsefloat(txtrate);       $('.txttotal').val(total);     }); }); 

and here html:

<table> <tr> <td><input type="text" class="txtquantity" /></td> <td><input type="text" value="12,3" class="txtrate" /></td> <td><input type="text" disabled="disabled" class="aspnetdisabled txttotal" /></td> </tr> </table> 

here fiddle

what missing? must trivial.

thanks

use decimal point . instead of comma (,) parsefloat read number properly.. working jsfiddle

<input type="text" value="12.3" class="txtrate" /> 

you should use decimal point when insert number other input. if still want use commas reason can replace commas points code: (thiis work both point , comma useage)

var txtquantity = $('.txtquantity').val().replace(/,/g,'.'); var txtrate = $('.txtrate').val().replace(/,/g,'.'); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -