please Help me for wrong return form NormalizeDouble( ) function

 

I want check all currency Bid price

NormalizeDouble( MarketInfo(TradePairs[i]+suffix,MODE_BID),MarketInfo(TradePairs[i]+suffix,MODE_DIGITS))

But this code return Wrong bid price For example return result for NZDUSD  0.7273500000000001

 
mehdi khoshbakhtvash:

I want check all currency Bid price

NormalizeDouble( MarketInfo(TradePairs[i]+suffix,MODE_BID),MarketInfo(TradePairs[i]+suffix,MODE_DIGITS))

But this code return Wrong bid price For example return result for NZDUSD  0.7273500000000001

You don't need to use NormalizeDouble() if you're using MODE_BID, unless you're doing something strange with the value.

That is the correct result for NormalizeDouble(). It is because of how floating point numbers are stored in binary

Example:

double MyVal=0.1;
printf("%.17f",MyVal);

Result: 0.10000000000000001

Just control the output when you want to display the number e.g. DoubleToString()

Why 0.1 Does Not Exist In Floating-Point
Why 0.1 Does Not Exist In Floating-Point
  • Rick Regan
  • www.exploringbinary.com
Many new programmers become aware of binary floating-point after seeing their programs give odd results: “Why does my program print 0.10000000000000001 when I enter 0.1?”; “Why does 0.3 + 0.6 = 0.89999999999999991?”; “Why does 6 * 0.1 not equal 0.6?” Questions like these are asked every day, on online forums like stackoverflow.com. The answer...
 
Price_Compare
Price_Compare
  • votes: 19
  • 2016.09.19
  • fxsaber
  • www.mql5.com
Elegant and nimble comparison of 'double' values of the "price".
 
honest_knave:

You don't need to use NormalizeDouble() if you're using MODE_BID, unless you're doing something strange with the value.

That is the correct result for NormalizeDouble(). It is because of how floating point numbers are stored in binary

Example:

double MyVal=0.1;
printf("%.17f",MyVal);

Result: 0.10000000000000001

Just control the output when you want to display the number e.g. DoubleToString()

Thanks a lot my firend
 
mehdi khoshbakhtvash: I want check all currency Bid price

NormalizeDouble( MarketInfo(TradePairs[i]+suffix,MODE_BID),MarketInfo(TradePairs[i]+suffix,MODE_DIGITS))

But this code return Wrong bid price For example return result for NZDUSD  0.7273500000000001

  1. NormalizeDouble returns a double - infinite digits - wrong use. Also your not understanding floating point - see price != price
    Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  2. Printf/PrintFormat or DoubleToString
 
For example
if ((CP(Lots, LotStep) >= MinLot) && ((CP(Price1, TickSize) == Price2))) // compare with the precision up to the second decimal place
  OrderSend...;
 
fxsaber:
For example
if ((CP(Lots, LotStep) >= MinLot) && ((CP(Price1, TickSize) == Price2))) // compare with the precision up to the second decimal place
  OrderSend...;
thank you