Quote from n00b7r4d3r:
One piece of information that you might already be aware of, but is important if you are not, is that division by integers will always equal integers even if the result is stored in a double.
More often that not, when I think I have a rounding problem it is because of this.
Here is an example of what I mean
int a = 3;
int b = 2;
double c = 0;
c = 3/2; //c has a value of 1, not 1.5
In this situation you must explicitly state that during the calculation you want these variables represented as doubles by casting them:
c = (double)3/(double)2; //c has a value of 1.5
I believe this is caused by the fact that the CPU carries out the calculation using the same registers to store the result as the original value, and since the original value was an int, the answer is an int.