How to work around the decimal problem in JavaScript?

advertisements

Possible Duplicates:
Strange problem comparing floats in objective-C
Is JavaScript’s math broken?
1.265 * 10000 = 126499.99999999999 ?????

After watching this I discovered that in JavaScript:

0.1 + 0.2 === 0.3

evaluates to false.

Is there a way to work around this?


How about

function isEqual(a, b)
{
  var epsilon = 0.01; // tunable
  return Math.abs(a - b) < epsilon;
}