jQuery addition error -


i have strange error going on. jquery function

jquery(document).ready(function(){   jquery("#new_customer").delegate(".kool", "keyup", function(event) {       var selectprod = jquery('.price, .qty',this);     var price = jquery('.price', this).val();     var qty =   jquery ('.qty', this).val();     var amount = price + qty;     var lineitemwrapperelement = selectprod.parent().parent();     jquery("input.amount", lineitemwrapperelement).val(amount);   });  }); 

instead of doing addtion "+" concatinating. i.e 12+1 coming 121 seems problem?? guidance do.

this happens because concatenate strings. have convert variables numeric type. assume price can float, can use parsefloat() function:

var amount = parsefloat(price) + parsefloat(qty); 

in order fix precision can use tofixed() after:

amount = amount.tofixed(2); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -