Off-topic MT4/mql4 questions. - page 45

 
Carl Emil Bograd #:
I simply try to do a simple 2 / 100 = 0.02, but it returns 0.0

try this

MessageBox("2/100: " + (string)(2.0/100.0) + "\n0.02");
 
Taras Slobodyanik #:
MessageBox("2/100: " + (string)(2.0/100.0) + "\n0.02");

I'm aware, that works.

Problem is doing calculations ran in the code of one of my EA's, I for some reason now have to specify these changes, which in no way was required for me before hand.
Just a few weeks ago my 2/100 = 0.02, but now its 0.
This is an issue and I imagine it would be for many who are recompiling their code.

 
Carl Emil Bograd #:

I'm aware, that works.

Problem is doing calculations ran in the code of one of my EA's, I for some reason now have to specify these changes, which in no way was required for me before hand.
Just a few weeks ago my 2/100 = 0.02, but now its 0.
This is an issue and I imagine it would be for many who are recompiling their code.

https://www.mql5.com/en/docs/basis/types/casting

Before operations (except for the assignment ones) are performed, the data are converted into the maximum priority type. Before assignment operations are performed, the data are cast into the target type.

   int    i=1/2;        // no types casting, the result is 0
   Print("i = 1/2  ",i);
 
   int k=1/2.0;         // the expression is cast to the double type,
   Print("k = 1/2  ",k);  // then is to the target type of int, the result is 0
 
   double d=1.0/2.0;    // no types casting, the result is 0.5
   Print("d = 1/2.0; ",d);
 
   double e=1/2.0;      // the expression is cast to the double type,
   Print("e = 1/2.0; ",e);// that is the same as the target type, the result is 0.5
 
   double x=1/2;        // the expression of the int type is cast to the double target typr,
   Print("x = 1/2; ",x);  // the result is 0.0