Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  50] [ 7]  / answers: 1 / hits: 24517  / 11 Years ago, thu, october 10, 2013, 12:00:00

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


More From » javascript

 Answers
8

Use toFixed() like



Total =Total.toFixed(1);


Or Simply,



Total = (parseFloat(subtotal)+parseFloat(tax)).toFixed(1);

[#75109] Tuesday, October 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;