I have read through a few examples if how to get my decimal point values down to 2 places but nothing I have tried seems to work with my current function I use to calculate subtotals .. Can anyone give me some advice on how to make this work correctly. (for example: I currently get values back like 1848.0198768 but need it to be just be 1848.02).
Here is my calculateSubTotal code:
function calculateSubtotal()
{
var sum = 0;
$(".clamount").each(function(i,e)
{
var v = parseFloat($(e).val());
if(isNaN(v))
{
v = 0;
}
if($(e).attr("data-column")=="pbDebit") v = -v;
sum += v;
});
$("#subtotal").text(sum);
$("#bTotalBookingAmount").val(sum);
I have tried the following to no avail:
// var subtotalNew = parseFloat($('#subtotal').text(sum).toFixed(2));
// $("#subtotal").text(subtotalNew);
// $("#bTotalBookingAmount").val(subtotalNew);
}
Any guidance would be greatly appreciated. I am assuming the code isnt working due to a NaN value (which I attempted to account for in the if(isNaN(v)) section, which it is always numbers and never any letter characters so I am a little confused.