I've ran into several oddities using javascripts floating point arithmetic, but I can never recall them off the top of my head!What are some common mistakes when using JavaScript to do math?
Common mistakes with javascript arithmetic
javascript;math;mistakes
The common problems with javascript arithmetic relate to the use of parseInt, or the lack of.Not using radix when converting strings to integers:parseInt(0137); // 95!parseInt(0137, 10); // 137Not using parseInt at all with arithmetic:var a = 2;alert(a + 5); // 25alert(a - 5): // -3!Misunderstanding floating point arithmetic (applies to all languages, not just JS):alert(23 * 1.40 == 32.2); // false, 23 * 1.40 is represented as 32.199999999alert((23 * 1.40).toFixed(1) == 32.2); // trueCalculating currency with floating points may lead to rounding errors, currency values should be treated as integers (multiplied with 100) before processing.