Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 is an object-oriented language?
Tarp999
46
Tarp999 2014.05.02 16:39 
double za = 100*67/750, zb = 100*142/250;
Alert(DoubleToString(za,2), "  ", DoubleToString(zb,2));

The program shows me: za = 8.00 and zb = 56.00

instead my calculator displays: za = 8.93 and zb = 56.80


Why? Why? Why? Why? Why?

GreenMoney
379
GreenMoney 2014.05.02 17:15  
GarZed9:

. . .

Why? Why? Why? Why? Why?

You are performing math operations on integers, and only after the operations are complete, the integer is cast to a double. See Typecasting.

Just use a double in the calculation.

Try:

double za = 100*67/750.0, zb = 100*142/250.0;
Alert(DoubleToString(za,2), "  ", DoubleToString(zb,2));

(Notice that I used 750.0 instead of 750 and 250.0 instead of 250)

whroeder1
13597
whroeder1 2014.05.03 00:58  
GarZed9:
double za = 100*67/750, zb = 100*142/250;

The program shows me: za = 8.00 and zb = 56.00

On MT4 v434, division quotient don't give floating point values(Bug??) - MQL4 forum
Tarp999
46
Tarp999 2014.05.03 07:43  
Thirteen:

You are performing math operations on integers, and only after the operations are complete, the integer is cast to a double. See Typecasting.

Just use a double in the calculation.

Try:

(Notice that I used 750.0 instead of 750 and 250.0 instead of 250)



Really thanks to all!
/
To add comments, please log in or register