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

 
fxsaber:

Yes, eight.

Why then.

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

Digits_values returns 4 ?

Result: 500000000.0001:4

 

How many digits after the decimal point are there?

void OnStart()
{
        double price = 5000000000.0001;
        Print( price, ":", GetDigits( price ));
}

Apparently so many that the computer can't even count.

Result: ????

 
A100:

Why then

Digits_values returns 4 ?

Result: 500000000.0001:4

Study the string conversion.

 
A100:

How many digits after the decimal point are there?

Apparently so many that the computer can't even count.

Result: ????

Yeah, like 1/3.

 
A100:

A good solution usually works correctly

I may not have checked everything, but when I tested it twice on MQL4, the output values were correct

 
fxsaber:

Study the cast to string.

What does this have to do with conversion? There is a source number 500000000.0001

The question is how many decimal places does it have? The answer is 4, and you have 8.

 
A100:

There is a source number 500000000.0001

There is no such number among the doubles. There is an approximate equal to it - 500000000.00010001016593933105. It is assigned to it.

 
A100:

What does this have to do with conversion? There is an initial number 500000000.0001

The question is how many decimal places it has? The answer is 4, and you have 8.

Not " you have 8", mql has 8 by default. Can't we read the documentation?

 
Alexandr Sokolov:

I think I am not the only one who had a rare situation where I needed to get the number of decimal places, and Digits() function works only with quotes, and besides there is no information about it anywhere (at least at the time of writing this post I have not found it before, so I want to show what solution I found).


As it turned out, the essence of the banal simple, but still has one drawback - this function does not recognize zeros, if after them there are no other digits. For example, the function will return 2 when followed by 0.01, but when followed by 0.0000 it will return 0 (i.e. it can't see four zeros). So, consider this shortcoming in your developments.


The code in MQL4



Aren't you a bit worried by the fact that your Value parameter is colored blue?

 
Алексей Тарабанов:

Aren't you the least bit bothered by the fact that you have the Value parameter in blue?

It is so here on the forum for some reason, but in the editor it is the same as usual

Reason: