Why does the division of two integers return 0.0 in Java? [duplicate]

Because the conversion to float happens after the division has been done. You need:

float percentage = ((float) totalOptCount) / totalRespCount;

You should be able to format using something like:

String str = String.format("%2.02f", percentage);

Leave a Comment