[Solved] How to get a floating point result from dividing two integers [duplicate]


Testing your code, it does indeed give 3.333, because the typecast takes precedence… did you execute some other code?


Another possible option is to typecast b.

rs = a / (float)b;

You could also typecast a, but you’d need an extra set of parenthesis.

Here’s an ideone demo.

3

solved How to get a floating point result from dividing two integers [duplicate]