Printing 12/110*100 always returning 0.0

int x = 12
int y =110

I need to print this either as double or float. It always shows as 0.0
float percentage =(float)(x/y);
newone2011Asked:
Who is Participating?
 
Peter KwanAnalyst ProgrammerCommented:
Since division of two integers (i.e. both nominator and denominator are integers) will only return integer value. Therefore, you may use either wdosanjos's comments or the following:

double percentage = x*1.0/y;
0
 
wdosanjosCommented:
Try:

float percentage = (float)x / y;
0
 
newone2011Author Commented:
Good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.