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

 
void OnStart()
{
        double price =  500000000.0001;
        Print( price, ":", d( price ));
}

Result: 500000000.0001:4

4, but not 8

 
All righty then... Bathe in this joy, if you like it.
 
A100:

You guessed it. And how many decimal places are there? 8?

I don't need to be tested.

  Print(NormalizeDouble(1234567890 + 1 e-7, 8) == 1234567890); // true
  Print(1234567890 + 1 e-7 == 1234567890); // true
 
fxsaber:

I don't need to be checked.

Nevertheless, you have corrected your code - so the check was helpful

 
Print ( 12345+1e-7)
 
A100:

Nevertheless, you corrected your code

Look at where the code was pulled from. And for what practical purpose it was intended. If it is not clear - for prices.

There was no foolproofing in the code because it was not intended to be used by such a user.

In the course of the discussion, it turned out that foolproofing must be implemented if the code is published. Otherwise it will be 5 pages of shit.

So, indeed, corrected. Once again, numbers with infinite Digits is the norm.

 
Dmitry Fedoseev:

I know how NormalizeDouble works, because I've played its full analogue.

It all depends a lot on what Digits you want to get. If double-representation, your code gives a different value. If digits of a numeric constant, it is correct (and not always).

 
Here we go again with the droppers...
 
fxsaber:

It all depends a lot on what you need to get.

You need one

int f( double );

so that (in particular)

void OnStart()
{
        Print( f( NormalizeDouble( 500000000.0001, 4 )));
}

result is equal to: 4

 
A100:

You need one

to

The result was: 4

Perhaps that is exactly the function you need. Answered the TS.

Forum on trading, automated trading systems and strategy testing

How to get the decimal places of any numbers (not only quotes) bypassing Digits() in MQL4 and MQL5

Alexandr Sokolov, 2018.11.03 17:39

I think I'm not the only one who faced a rare situation when I needed to get the number of decimal places

Reason: