Subtracting 2 doubles

Alon D  

I have this code:


   double previousBar_open = (double)iOpen(_Symbol,PERIOD_CURRENT,1);

   double previousBar_close = (double)iClose(_Symbol,PERIOD_CURRENT,1); 



   double previousBarDifference = NormalizeDouble(previousBar_close - previousBar_open, _Digits);

   Print (previousBarDifference);


But I get results like -1e-05 or 5e-05   sometimes.

And sometimes I get a normal value like 0.00011

Why?



Keith Watford  
Print (DoubleToString(previousBarDifference,_Digits));

Please edit your post and

use the code button (Alt+S) when pasting code

William Roeder  
Alon D: But I get results like -1e-05 or 5e-05   sometimes.  And sometimes I get a normal value like 0.00011

Floating-point has an infinite number of decimals, it's your not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
          Double-precision floating-point format - Wikipedia, the free encyclopedia

See also The == operand. - MQL4 programming forum

If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
          question about decima of marketinfo() - MQL4 programming forum 2016.05.18

Reason: