0

I have a script to calculate checkboxes as they are selected:

$('input:checkbox').change(function () {
  var total = 0;
  $('input:checkbox:checked').each(function () {
    total += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
  });
  $("#total").val(total);
});

The total is showing as 46 rather than 46.00 for example. How can I ensure the number is always showing to 2 decimal places?

I added

console.log(format(total));

Which showed the correct format...

Andy
  • 61,948
  • 13
  • 68
  • 95
Vogal
  • 104
  • 6

1 Answers1

2
total = parseFloat(total).toFixed(2);
404Exist
  • 89
  • 6