Convert Last 2 Digits of a double to zeros

 
Pair= "EURUSD";

Lev00Ask = NormalizeDouble (MarketInfo(Pair,MODE_ASK),3);
           Print (Pair," Lev00Ask = ", Lev00Ask);

I'm learning to code.

When I execute this code, it gives me "Lev00Ask = 1.133"

I want to convert the result to 1.13300 and use it in my next calculation.

I've not been able to find a way around it.
Any help is appreciated.



 
peterbabs: 1.133" I want to convert the result to 1.13300 and use it in my next calculation.
  1. Your question makes no sense. A double has infinite digits, always. If you want to see the extra zeros when you print it
    string   price_as_string(double price){return DoubleToString(price, _Digits);     }
    

  2. You want to use it, just use it.

  3. If you want to convert a price to the lower level:
    Lev00Ask = MathRoundDown(MarketInfo(Pair,MODE_ASK),100*_Point);
    double MathNearest(  double v, double to){ return to * MathRound(v / to); }
    double MathRoundDown(double v, double to){ return to * MathFloor(v / to); }
    double MathRoundUp(  double v, double to){ return to * MathCeil( v / to); }
    
              MT4:NormalizeDouble - General - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
 
whroeder1:
  1. Your question makes no sense. A double has infinite digits, always. If you want to see the extra zeros when you print it

  2. You want to use it, just use it.

  3. If you want to convert a price to the lower level:
              MT4:NormalizeDouble - General - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum


Thank you for responding.

I created a function to check if a BuyStop order exist at a certain price. If not, it should place an order at that price.

But it always return false. I reckon it's because I'm comparing Lev00Ask 1.133 with OrderOpenPrice() which is 1.13300.

Please see code below

bool BuyStopExistAtLev00()
{    for( int i=OrdersTotal()-1;i>=0;i-- ) {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
        && OrderSymbol()==Pair 
        && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) 
        && OrderOpenPrice()==Lev00Ask)
          return(true); }  
           return (false); }    
 
peterbabs:


Thank you for responding.

I created a function to check if a BuyStop order exist at a certain price. If not, it should place an order at that price.

But it always return false. I reckon it's because I'm comparing Lev00Ask 1.133 with OrderOpenPrice() which is 1.13300.

Please see code below

This is a feature of double. Doubles are rarely equal. You should compare a difference. See the example below.

bool BuyStopExistAtLev00()
{    for( int i=OrdersTotal()-1;i>=0;i-- ) {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
        && OrderSymbol()==Pair 
        && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) 
        && fabs(OrderOpenPrice()-Lev00Ask)<_Point*0.1)
          return(true); }  
           return (false); }
 
Petr Nosek:

This is a feature of double. Double are rarely equal. You should compare a difference. See the example below.


That is brilliant, Petr Nosek!!!!
You have rescued me!
I appreciate!