How to remove the extra digits of the fetched prices from MqlRates?

 

Hi guys,

I'm using this code to fetch the close price of the previous candle

MqlRates mrate[];
double Close_Price;

Close_Price=mrate[1].close;

Sometimes I get the correct price (1.12086) and other times I get a wrong price (1.1208600000000001)

How can I remove all of these extra digits?

 
ImperialTrader: Sometimes I get the correct price (1.12086) and other times I get a wrong price (1.1208600000000001)

Wrong, they are both the same exact price.

Floating-point has 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

Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

 
William Roeder:

Wrong, they are both the same exact price.

Floating-point has 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

Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

Ok, thank you.