The result of calculation is not 30.30303030
but 0
because
60 / 99
is calculated. The result is truncated toward zero because this is integer division and the result is 0
50 * 0
is calculated. The result is 0.
You should do the calculation using double
.
#include <stdio.h>
#include <math.h>
int main()
{
int n = static_cast<int>(50.0 * (60.0 / 99.0));
printf("Floor: %d\n", n);
return 0;
}
Using 50 * (60.0 / 99)
or 50 * (60 / 99.0)
instead of 50.0 * (60.0 / 99.0)
is also OK because other operands will be converted to double
to match types, but using 50.0 * (60 / 99)
isn't good because 60 / 99
is 0.