I would like it so that each time a (toppings) checkbox is checked, it updates the price by adding an additional 99 pence. It all works fine, except when the user selects the 3 checkboxes (which is 0.99 * 3) and it displays 2.9699999999999998
instead of 2.97
Any ideas on what's wrong?
HTML:
<label><b>Toppings (99p Each): </b></label><br>
<input type="checkbox" name="onions">Onions</input><br>
<input type="checkbox" name="mushrooms">Mushrooms</input><br>
<input type="checkbox" name="peppers">Peppers</input><br>
<input type="checkbox" name="olives">Olives</input><br>
<input type="checkbox" name="garlic">Garlic</input><br>
<input type="checkbox" name="xtra-cheese">Xtra Cheese</input><br>
<input type="checkbox" name="peperoni">Peperoni</input><br>
JavaScript:
var pizzaCost = 0.00;
var toppingCost = 0.00;
$('input[type=checkbox]').change(function(){
var checked = $(":checkbox:checked").length;
var checkedInt = parseFloat(checked, 10);
var temp = (0.99 * checkedInt);
toppingCost = parseFloat(temp);
var total = pizzaCost + toppingCost;
$("#totalPrice").text(total);
});