double treated as integer - never seen bug?

 

The math is simple:

155/32 = 4.84375

Not here:

void OnTick()
  {
   double tmp = 155/32;
   Print(tmp);
   MessageBox(DoubleToString(tmp,3));
}


I do not have any clue wath went wrong here!

 
Zar88:

The math is simple:

155/32 = 4.84375

Not here:


I do not have any clue wath went wrong here!

Change to this:
void OnTick()
  {
   double tmp = 155/32.;
   Print(tmp);
   MessageBox(DoubleToString(tmp,3));
}

If you want a detailed explanation, have a read of the "Typecasting of Numeric Types" section of this article - https://docs.mql4.com/basis/types/casting 

Typecasting - Data Types - Language Basics - MQL4 Reference
Typecasting - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Typecasting - Data Types - Language Basics - MQL4 Reference
 

I know typecasting - thats why i wonder:

int/int => double ??

double ??" alt="int/int => double ??" style="vertical-align: middle;">

 

You supplied 2 integers (155 and 32).

The result was then cast as a double.

Something like this:

int    int_tmp = 155/32;
double dbl_tmp = (double)int_tmp;
 
thanx