Get the number of decimal places of any numbers (not just quotes) bypassing Digits() in MQL4 and MQL5 - page 9

 
Mesaoria:

That's not what I was talking about at all. The idea of converting a duble to a string so that you can then count the characters in the string is a complete nonsense. No matter what you do.

What's the big deal? So far, this option is the fastest, most functional and guaranteed correct. What are your options?

 
Alexandr Sokolov:
Yes, my variant is probably not the best, but since I've never found anything about it before, it's the best I came up with on my own, I commented above, while you didn't suggest your own variant.

I compared these variants:

int ds(double v){
   string s=(string)v;
   int l=StringLen(s);
   int n=l-StringFind(s,".",0)-1;
   if(StringSubstr(s,l-1,1)=="0")n--;
   return(n);
}

int d(double x){
   int n;
   for(n=0;n<8;n++){
      if(x==NormalizeDouble(x,n)){
         return(n);
      }
   }
   return(n-1);
}

The string variant is slightly faster, and it's not limited to 8 digits like d(). And the guarantee of correctness is counting by the way the terminal displays the number.

I choose the variant with conversion to string.

 
Dmitry Fedoseev:

What's the big deal? So far, this option is the fastest, most functional, guaranteed to be the right one. What are your options?

Can you name at least one case of applying the above algorithm?

 
Mesaoria:

Can you name at least one case of applying the above algorithm?

There was one case for the trading panel to output the lot size with the correct number of decimal places in the text field. This is the only case.

 
Dmitry Fedoseev:

There was one case for the trading panel to output the lot size with the correct number of decimal places in the text box. This is the only case.

I.e. it outputs "1" in case of 1 lot and "0.01" in case of 0.01 lot?

 
Mesaoria:

So it outputs "1" in the case of 1 lot and "0.01" in the case of 0.01 lots?

Not exactly. It depends on the minimum lot and the lot step. If the minimum lot is 0.01, then 1 is displayed as 1.00

 
Dmitry Fedoseev:

Not really. Depending on the minimum lot and the lot increment. If the minimum lot is 0.01, then 1 is displayed as 1.00

O.o.

So it turns out you're not using your function, but still displaying something like DoubleToString(LotSize, <some const value>), no?

 
Mesaoria:

O.o

So it turns out that you don't use your function, but still output something like DoubleToString(LotSize, <some const value>), no?

Yes. But you have to know how many decimal places to output.

 
Dmitry Fedoseev:

Yes. But you have to know how many decimal places to output.

In other words, do you use the min.lot (or lot increment) entered by the user to determine how many decimal places this value has, and then save it to normalise future values?

 
Mesaoria:

So you determine from the min.lot (or lot increment) entered by the user how many digits after the decimal point there are, and then save it to normalise future values?

What don't you understand? Price has Digits(), while volume doesn't. This is how it is calculated.

Why do you need volume digits? The same reason we need the price digits!

Reason: