Fraction problem

Hi rooter,

I got a simple question. When I tried to calculate a fraction say 33/99 by root. I cout <<33/99<<endl; but I got 0 instead of 0.33333. How could I obtain decimals instead but not an integer as result?

Since both are integers, the operation is called for integers. For float or double operation, at least one of the numbers should be a float or double; e.g.

1.0 * 33 / 99
33.0 / 39
(double)(33)/99

etc. but not (double)(33/99), since the integer 33/99 would be done first, giving zero.

2 Likes

Thanks so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.