Dividing two numbers

 

I think I am overlooking something patently obvious here

    myVal = GlobalVariableGet(Symbol()+"_ADR_R5"); 
    double ratio;
    ratio = myVal/totalR;
    logInfo(FULL, "getVars", "myVal = "+myVal+"  totalR = "+totalR+"  ratio = "+DoubleToStr(ratio, 2));

The results of the print out statement (logInfo) return 130 for myVal, 288 for totalR, and ZERO for ratio

Why???? ratio is declared as a double

EDIT:

So it looks like MQ4 assumes you are doing integer arithmetic if all the values in an expression are integers, even if the variable the result is being stored in is a double. DUH. Better times 1.0 then (myVal * 1.0 / totalR).

 
HarriMQL4:

I think I am overlooking something patently obvious here

The results of the print out statement (logInfo) return 130 for myVal, 288 for totalR, and ZERO for ratio

Why???? ratio is declared as a double

EDIT:

So it looks like MQ4 assumes you are doing integer arithmetic if all the values in an expression are integers, even if the variable the result is being stored in is a double. DUH. Better times 1.0 then (myVal * 1.0 / totalR).

What you are overlooking something patently obvious was that you didn't tell us what type myVal, and totalIR and the values assigned to them.

It's type casting https://docs.mql4.com/basis/types/casting , been asked too many times in forum https://www.mql4.com/search#!keyword=typecasting&module=mql4_module_forum&page=1 

 
HarriMQL4:
The results of the print out statement (logInfo) return 130 for myVal, 288 for totalR, and ZERO for ratio
Why???? ratio is declared as a double

130/288 = zero. Thus ratio = Double(0) = 0.0

On MT4 v434, division quotient don't give floating point values(Bug??) - MQL4 forum

 
Thank you and thank you, I was not aware.  Now I know why (and perhaps more importantly, to search a little harder for the answer beforehand)