I'm trying to subtract two values and it is giving me different results

 

Hello, 

Right now I have two values for the high and open for the last bar but when trying to subtract them it gives very different results and I have trying for hours to discover why this happens with no luck :(. I'm a beginner so i know I'm missing something. 

             HIGH          OPEN

113.4999999999995  ---- 113.3999999999995

The two values are stored in variables but when subtracting the variables I got this.   

EXPECTED RESULT : 0.1000000000000085

THE RESULT I GOT : 0.09999999999999432

 
Ahmed Gamal:

Hello, 

Right now I have two values for the high and open for the last bar but when trying to subtract them it gives very different results and I have trying for hours to discover why this happens with no luck :(. I'm a beginner so i know I'm missing something. 

             HIGH          OPEN

113.4999999999995  ---- 113.3999999999995

The two values are stored in variables but when subtracting the variables I got this.   

EXPECTED RESULT : 0.1000000000000085

THE RESULT I GOT : 0.09999999999999432

It's normal, floating point variables have limited precision.

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
 

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

See also The == operand. - MQL4 programming forum (2013)

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)

 
Alexandre Borela #:
It's normal, floating point variables have limited precision.

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Okay I didn't understand everything but I do the same code in python and it returns "  0.1000000000000085 " while it returns "  0.09999999999999432" on mql4 so how can i get the same result on mql4 or at least get the opposite result in python as i want the two answers to be uniform.

also i didn't mention that the variables are declared as doubles. 

Thank you.