Problem with arithmetics

 

Hi guys,

I'm new here, coming from MT4. I have a problem and I don't know what is wrong. I want to divide the result of two functions stored in float variables, but the print is giving me zero. I found the error source to be the following, if I type "double a = 2/4; Print(a);" in the OnInit() or the OnTick() functions and I run it, the console returns me "0.0". It happens in all the cases where the result should be <1.

On more examples, 4/2 returns 2, 6/2 returns 3, but 5/2 also returns 2, so I think it is basically killing the decimal part. If I try with double variables, it behaves the same.

Have you any idea on why is this happening and how can I get over it?

Thanks a lot in advance.

 

It's Type Casting . . .   instead do . . .

 

double a = 2.0/4.0; 
Print("a is: ", a);
 
RaptorUK:

It's Type Casting . . .   instead do . . .

 

Worked. Great help, I did't know what else do.. Thanks for the link too.
 
Will404:
Worked. Great help, I did't know what else do.. Thanks for the link too.
Anyway the same is true for MT4
Reason: