I am writing some where I need to divide 29 by 10. But when I do so and store it in a double, it outputs 2.0000 instead of 2.9. Can someone explain why this is happening and how to fix it?
double a = 29/10;
double works as expected, it's just that you are not assigning it an expression of type
What you assign it is an
int, a result of dividing
int. This is
2, because the remainder is discarded when you divide integers.
10.0 will fix this problem.