correct? variable/100 = zero?

 

Please explain why the MT4 result is 0 rather than .01 ?  thanks.

 

int number=1;

double Perc_As_Decimal = number/100;  
  
//-- result expected: .01

Print("result = "+Perc_As_Decimal);
result = 0



 

You must declare variable "number" as double or make type cast:

double Perc_As_Decimal = (double)number/100;  
 
Janusz Trojca:

You must declare variable "number" as double or make type cast:

Thanks Janusz.
 
Brian Kester:
Thanks Janusz.
you're welcome
 
Brian Kester:

Please explain why the MT4 result is 0 rather than .01 ?  thanks.

 


yes variable as double and than

for print use

DoubleToString for limit 2 dec for not get 0.00999999999999999 (it happen) and avoit error in compile

Print("result = "+DoubleToString(Perc_As_Decimal,2) );
Reason: