MQL5 devision returns zero ?

 

hi

Look at this part of code. It prints 0. I don't know why!

Any idea?




int  risk_percent = 10;
   
Print(risk_percent/100);
 
0.1 is 're-converted' to an int and so 0.1 becomes a rounded 0.
 
Carl Schreiber:
0.1 is 're-converted' to an int and so 0.1 becomes a rounded 0.
I changed variable type to 'double' and problem solved! thanks!!
 
Carl Schreiber: 0.1 is 're-converted' to an int and so 0.1 becomes a rounded 0.

You have the right idea, but no it never gets re-converted. It remains an integer during the entire process. It carries out integer division, not floating-point division.

In integer division, if the divisor is greater than the numerator, then the results are always 0.