int and double

 

Feel free to ignore this if you want, it's a little simple, but I hope someone can explain this aspect of programming to me?

I tried to find the number of points between 2 prices (i.e. an integer like 10 points, or 2 points).

      int    origSLpoints  = (SLprice-askprice)/Point;
      double origSLpoints2 = (SLprice-askprice)/Point;

I kept getting errors and I finally tracked it down to the first line of code.

Changing it to a double fixed the problem, even though the answer from the equation will always be an integer.

I remember now, when I wrote it I was a bit iffy as to which to use, but generally go for int if possible for efficiency.

Can anyone explain to me what I should to next time I get a similar situation?

 
alladir: I kept getting errors and I finally tracked it down to the first line of code.
  1. There are no mind readers here. "getting errors" says nothing.
  2. Post all the relevant code.
    (SLprice-askprice)
    Where are the definitions?
 

They are just prices.... ask price and stop loss price... it's finding the difference between them and dividing by Point to get the number of points between the two.

E.g. something like

double SLprice  = 1.11111
double askprice = 1.11121

so in this case, the difference is 10 points

But my question is, since the answer is always an integer, why do I need it to be a double variable to get the correct answer?


(Yeh, not so much an MQL question, but a programming question.. I assumed some well-known principle amongst programmers)

Reason: