2/(n+1) evaluates to 0

 

Hi all

I'm calculating an EMA and the simple expression:

int period;
double sf;

sf = 2/(period+1);

ALWAYS EVALUATES TO 0. Even if I hard code the values in, like sf=2/(14+1) it still gives me 0.

For the life of me I can't understand why.

Please any advice?


Thanks!

 
sf = 2./(period+1);
 
Alain Verleyen:

Damn Alain how do you do it? Thank you very much!

 
CobusSteyn0105:

Damn Alain how do you do it? Thank you very much!

Issue a old as computers.

Forum on trading, automated trading systems and testing trading strategies

On MT4 v434, division quotient don't give floating point values(Bug??)

Nelson Almeida, 2012.09.18 17:15

I don't know why, but when i was making an indicator, i can't obtain a correct division.

Is this bug or is missing me something??

Example:

double ResultOf=5/2;

// Should give the Result of 2.5, however in comment i have 2.
// Anyone knows why?? or is one more Bug??


Reason: