Download MetaTrader 5

Problem with arithmetics

To add comments, please log in or register
Do you need private account monitoring? The Signals will provide you one!
Will404
87
Will404 2013.07.08 16:29 

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.

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.07.08 16:33  

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

 

double a = 2.0/4.0; 
Print("a is: ", a);
Will404
87
Will404 2013.07.08 16:52  
RaptorUK:

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

 

Worked. Great help, I did't know what else do.. Thanks for the link too.
Alain Verleyen
Moderator
30755
Alain Verleyen 2013.07.08 19:14  
Will404:
Worked. Great help, I did't know what else do.. Thanks for the link too.
Anyway the same is true for MT4
To add comments, please log in or register