A weird mathematics problem.

 

I meet a  weird mathematics problem. Does any expert help me resolve this problem ?

 

   double BasicLot=0.1;

   int MaxPosition=7;

   double TotalLots = (BasicLot * MaxPosition);   

   if(TotalLots == 0.7)

      Alert("TotalLots == 0.7");

   else if(TotalLots > 0.7)

      Alert("TotalLots > 0.7");

   else

      Alert("TotalLots < 0.7");


The alert result  unexpectedly is "TotalLots > 0.7".  What's wrong in this code and result ?

The attachment is the source code of this testing script. 

Files:
test.mq4  1 kb
 
4xidea:

I meet a  weird mathematics problem. Does any expert help me resolve this problem ?

 The alert result  unexpectedly is "TotalLots > 0.7".  What's wrong in this code and result ?

It's an issue to do with comparing double variables . . .  read this thread:  Can price != price ?
 

I got the problem and solution. Thank you, RaptorUK.

My code is changed to as below, and it works fine.

   double BasicLot=0.1;

   int MaxPosition=7;

   double TotalLots = (BasicLot * MaxPosition);   

   if(NormalizeDouble(TotalLots, 2) == NormalizeDouble(0.7, 2))

      Alert("TotalLots == 0.7");

   else if(NormalizeDouble(TotalLots, 2) > NormalizeDouble(0.7, 2))

      Alert("TotalLots > 0.7");

   else

      Alert("TotalLots < 0.7");
Reason: