Integer division is rounded down, so if your answer is less than 1, you will get 0.
You can try something like this:
printf("%d\r", ((current*100)/total));
However, you always get an integer.
If you produce a numerator in a float, you will get a floating division and the correct answer.
printf("%f\r", ((float)current/total * 100));
However, you can trim the zeros after, for example, for three digits to a decimal and after you can use:
printf("%3.2f\r", ((float)current/total * 100));
Departure:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
source share