I assume currentSize
and totalSize
are int
.
currentSize = 4079;
totalSize = 500802;
If they are, then currentSize/totalSize
is an integer division. The result will have no fractional part (the fractional part is removed, no round up). Therefore the result is 0
.
If one of the operand is double, the result of division will have fraction. Therefore, I cast one integer operand to double.
(double) currentSize
After the calculation, if you want the result to store in int
, you have to cast (convert double to int; remove fractional part).
int percentage = (int) ((double) currentSize ...
The whole code is:
int currentSize = 3;
int totalSize = 100;
int percentage = (int) ((double) currentSize / totalSize * 100);
System.out.println(percentage);