lundi 13 juillet 2015

jQuery, upto 2 trailing digit after decimal

Following is the jQuery code

    $('#Cancelation').change(function(){        
        if($(this).is(':checked')){
            total = parseFloat($('#TotalAmount').val()) + parseFloat($('#Cancelation').val());                      
        } else {
        total = parseFloat($('#TotalAmount').val()) - parseFloat($('#Cancelation').val());
        }
        $('#TotalAmount').val(total);
        $('#TotalPrice').html(total);
    });

If the #TotalAmount value is 10.49 which shows correctly on page load and problem is that if checkbox checked or unchecked, value of checkbox which is 2.00 added or subtract from #TotalAmount and #TotalPrice but the output shows like 12.48999998 on add 0r 10.48999998 on subtract.

I tried .toFixed(2); but the result is same, any other way to fix the issue?




Aucun commentaire:

Enregistrer un commentaire