Integer division

To add comments, please log in or register
sd59
636
sd59  
int x = 3, y = 6;
double z;

z = y/x  ------  z = 2

z = x/y  ------ z = 0

z = (double)x/y ------ z = 0

MQL4 documentation identifies this problem but the trouble is it doesn't say the correct way to get the right answer!!

Is the only way to get the right answer to declare x & y as 'double' even though in the program they are clearly integers?

Mohamad Zulhairi Baba
16412
Mohamad Zulhairi Baba  
sd59:

MQL4 documentation identifies this problem but the trouble is it doesn't say the correct way to get the right answer!!

Is the only way to get the right answer to declare x & y as 'double' even though in the program they are clearly integers?

z = x/(double)y;
sd59
636
sd59  
Doh! The simplest things.......Thanks!
To add comments, please log in or register