Download MetaTrader 5

correct? variable/100 = zero?

To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
Brian Kester
818
Brian Kester 2016.09.17 12:52 

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
8575
Janusz Trojca 2016.09.17 12:59  

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

double Perc_As_Decimal = (double)number/100;  
Brian Kester
818
Brian Kester 2016.09.17 14:58  
Janusz Trojca:

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

Thanks Janusz.
InvestSoft
8575
Janusz Trojca 2016.09.17 16:24  
Brian Kester:
Thanks Janusz.
you're welcome
Bernhard Schweigert
5743
Bernhard Schweigert 2016.09.17 21:50  
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