Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  5] [ 2]  / answers: 1 / hits: 27354  / 11 Years ago, fri, may 17, 2013, 12:00:00

I want to make multiplication using JavaScript.



Multiplication of 2 and 0.15 is 0.3 but 3 and 0.15 is 0.44999999999999996. I want to get 0.45 such as result. How can I do it with JavaScript?


More From » javascript

 Answers
114

It's a rounding error. You may want to round your number to a fixed amount of digits, like this:



parseFloat((your_number).toFixed(2));

[#78163] Thursday, May 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;