This looks like a mt4 error Comment(DoubleToStr(10/100,5))

 

if i write this in a expert advisor:


Comment(DoubleToStr(10/100,5));


he show me on chart as result: 0.00000


but 10/100 must be 0.1

 

10/100=0

10./100=10/100.=0.1

 
PipTraderTim:

if i write this in a expert advisor:


Comment(DoubleToStr(10/100,5));


he show me on chart as result: 0.00000


but 10/100 must be 0.1

In case you didn't get it from the earlier posts, the whole number (integer) result of dividing 10 by 100 is zero. If you do it with decimals (doubles) then you get the answer you seek.

Another example would be 5/2 = 2 and not 2.5 or 2 + 1/2. Integer maths only deals in whole numbers so you just leave off (truncate) the fractional parts.

 

thanks for the answer, if you define a double variable:

double a=10;

and calculate

10/100

then it again gives zero result and dont accept or convert the variable a to 10.0 it just looks to the variable 10 like it a integrer value

 
PipTraderTim:

[...] then it again gives zero result and dont accept or convert the variable a to 10.0 it just looks to the variable 10 like it a integrer value

Okay, I'll have a go...

10 is interpreted by MT4 as an integer value. 10.0 is interpreted as a double value. If you want to calculate 10/100 then you need to do any of 10.0/100 or 10/100.0 or 10.0/100.0.

double a = 10/100 is the same as the 5th example at https://docs.mql4.com/basis/types/casting, which gives the result 0.
 

Try this script ...

int start(){
   
   Comment("");
   
   double a= 10;
   int b = 100;
   
   Print( "result is " + (a/b) );
   Comment( "result is " + (a/b) );
   
   return(0);
}

The result is 0.1000000 because when a double interacts with an int the double wins and the int is converted into a double before the mathematical operation is carried out.

A variable of type int, and integer, can only store a whole number.

A variable of type double, a double precision floating point number, can only store a number represented with a decimal point.

 

Well I was coding something at work in VB.net (for my sins) and found a related quirk of this language. I did the usual trick for rounding numbers ...

Dim max as integer = 123456
max = 1000 * (max/1000)

and it didn't round the number at all. I'm going WTF!

Run it through the debugger. Not working.

WTF?


Fortunately the guy who inflicted the VB on me was nearby. "What's the story?", says I.

Oh, says he, VB "knows" that it needs to promote those to doubles before doing the divide to protect you from yourself.

So you need to write ...

max = 1000 * (max\1000)

to get it to do an integer divide.

So for anybody who is used to VB, the proper integer divides that occur in every other programming language you can think of must seem weird.

Now I need to chill out,

think calm thoughts,

and forget that I have more VB to do tomorrow :-(

 

Yeah thats VB. God how i hate this language. (I used to write even 2d games in VB ;) )

When i only see "Dim something as integer". writing a whole sentence which could be done in a simple "int something";

As next: Code without {} is only hard to read.

Well, old language i guess ;)

Reason: