0 != 0.00000 ??

 

Any idea why this code snippet gives the below output?

double result = currentStopLoss - prevBarTrendDown;

if(result== 0) {

Print("Result is 0");

} else {

Print("Result is not 0: " + DoubleToStr(result, Digits));

}

[/CODE]

Output's : [CODE]Result is not 0: 0.00000
 

we need to know more about the folowing variabes

currentStopLoss

& prevBarTrendDown

it seem that they have the same amount

for that the result is 0.0000

 

because digits is 5, and the non-zero digit appears later on? Example: 0.000001

 

Probably because the one line should read:

if (Result == 0.0) {

0 is an int(eger), while 0.0 is a double, which is the same as Result in the comparison. When you compare integers with doubles, different things can happen. Or even better:

if (Result < 0.0001) {