I entered the following code (and had no compiling problems or anything):
float y = 5/2;
5 is an
2 is an
5/2 will use integer division. If you replace
2.0f), making one of the
float, you will get floating point division and get the
2.5 you expect. You can also achieve the same effect by explicitly casting either the numerator or denominator (e.g.
((float) 5) / 2).