'If' condition problem

 

Hi,

I am trying to create a loop with range of parameter called 'level'. This parameter is type of double.

I wrote the following lines:

Print("level ",level);
if(level == 0.9222 )
{
Print("level has been reached");
}

This condition is always false even I see that level 0.9222 is being reached (in the log file).

Can someone tell me please what is the problem?

Is 'if' condition works on 'double' type?

Thanks,

Ziv

 

Don't use " == " with doubles if possible.

Doubles don't compare for equality easily.

Search this forum for "NormalizeDouble" and see the problems others have encountered.

 
Another "classical" approach is to define following function:

bool Equal(double va11, double val2)

{

double delta = 1 * Point; // set your own value

if(MathAbs(va11 - val2) <= delta)

return(true);

else

return(false);

}

and then make following comparison:

if(Equal(level, 0.9222))

{

Print("level has been reached");

}