The expression, including the types of subexpressions, is evaluated from inside to outside:
double texturefactor = ((a / b) * 10);
When the compiler analyses a / b
, it has no idea that the result will later on be converted to double
, so it just compiles the computation as an integer division.
Explicitly casting one of the two operands to double
right there is enough to avoid that confusion:
double texturefactor = (((double)a / b) * 10);