Rounding the numbers
When we divide 200/300, the answer is 0.66666666. To get 0.66 as answer, I have declared
double percentage = 200/300;
But I am getting answer as 0.0. I should get the answer as 0.66(with 2 decimal points).
Can some one help me on this?
Re: Rounding the numbers
200 is an integer
300 is an integer
result will be an integer therefore the answer will be 0 as the fractional part is truncated.
You will need to cast at least one of your values to a double to get a double result.