Download MetaTrader 5

correct? variable/100 = zero?

To add comments, please log in or register
Brian Kester
820
Brian Kester  

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



InvestSoft
8906
Janusz Trojca  

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

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

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

Thanks Janusz.
InvestSoft
8906
Janusz Trojca  
Brian Kester:
Thanks Janusz.
you're welcome
Bernhard Schweigert
8286
Bernhard Schweigert  
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) );
To add comments, please log in or register