I hate to add to the litany of questions regarding this subject but I dont know where else to turn for a concise answer so here goes:
I have this form on jsFiddle
I got to this point by combining several different examples I have found online today to get the overall effect I wanted.
While researching I found a lot of posts talking about the hazards of adding floats. I believe I understand the concept of why this is normally a bad idea regarding precision. However, its seems like this is only really an issue when the sum of the two numbers is given with several decimal places. (like 6 or more)
In my code i will only ever add numbers that have 2 decimal places and I use
var n=val.toFixed(2); to make sure the result has 2 and only 2 decimal places. When testing everything seems to work great.
My question is twofold:
Is this an acceptable way to achieve my desired result and maintain precision given that I only need 2 decimal places?
Can you point me to an example that shows a better or more accepted way to do what I want?
With all due respect (and I owe this community a lot of respect) I know that "client side validation does not replace server side validation" and I only need to support Chrome so if anything in my code doesn't work as expected in any other browser that's not an issue.