« Tip of the day: Start… | Home | MBS Xojo / Real Studi… »

Tip of the day: Double comparison

Just run into the problem this week that double comparison often works, but also fails unexpected in an application. This remembers again to use comparison with tolerance for double variables. Like here with abs() and a 0.01 tolerance:

dim d as Double = 10 dim e as Double = 1.19 dim f as Double = d * e // checking exact fails if 11.90 = f then Break else Break end if // better check with tolerance if abs(11.90-f) < 0.01 then Break else Break end if
The biggest plugin in space...
11 09 14 - 10:34