For the last hour I’ve tried several different solutions but none have solved my problem.
I have various input fields containing a decimal number (price of product) e.g. 98.00.
Looping through a list of items, I need to add the fields together:
// Calculate sub-total
$('.selected_list li.order_line:visible').each(function(){
var item_cost = $(this).find('input.item_cost').val();
sub_total = sub_total + item_cost;
})
How can I add these items and get a result containing two decimals?
My fiddle here: http://jsfiddle.net/EgGUm/
Use parseFloat:
More, here