Download MetaTrader 5
To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Sujana Lius
7
Sujana Lius 2015.09.14 09:28 

Hi,

I'm trying to get the number of decimal digits from a number.

for example

0.1234 ---> 4

0.465 ---> 3

0.51 ---> 2 

 So far, I can only a similar function from this function

MarketInfo(Symbol(),MODE_DIGITS);

But that doesn't really help me. I need to get the number of decimal digits which I get from

MarketInfo(Symbol(),MODE_LOTSTEP);

So if I get '0.01' the output will be '2'

Any suggestion will be greatly appreciated. 

Thank you in advance

whroeder1
13644
whroeder1 2015.09.14 12:23  
sliu152: I'm trying to get the number of decimal digits from a number.
  1. Try:
    Not compiled, not tested.
    #define LOTS double
    string   lots_as_string(LOTS lots){   
       static int  lotDigits = EMPTY;   if(EMPTY == lotDigits)
          lotDigits   = digits_in(MarketInfo(_Symbol, MODE_LOTSTEP) );   
       return DoubleToStr(lots, lotDigits);
    }
    int digits_in(double d){
       int digits = 0;
       while(d - int(d) > 1.E-8){
          d *= 10.0; ++digits;
       }
      return digits;
    }
    Not compiled, not tested.
  2. If you just want to print a number without trailing zeros:
    string  to_variable(double value){
       return StringFormat("%g", value);
    }
/
To add comments, please log in or register