Adding float values using jQuery
used code:
result variables:
subtotal = 4.6;
tax = 2.3;
Total = parseFloat(subtotal)+parseFloat(tax);
i got result 6.8999999999999995... why it not returning the correct value 6.9
Adding float values using jQuery
used code:
result variables:
subtotal = 4.6;
tax = 2.3;
Total = parseFloat(subtotal)+parseFloat(tax);
i got result 6.8999999999999995... why it not returning the correct value 6.9
Use toFixed() like
Total =Total.toFixed(1);
Or Simply
,
Total = (parseFloat(subtotal)+parseFloat(tax)).toFixed(1);