Dividing two integers to produce a float result [duplicate]

Cast the operands to floats:

float ans = (float)a / (float)b;

Leave a Comment