Java Calculate Percentage

Calculating percentage in java is very easy. Just follow the simple mathematics, No need to do anything extra. The math is:

Gained value / total value * 100.

That’s it. Here is the java code:

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Percentage {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double totalValue = 500; //use your value
double gainedValue = 356; //use your value
double percentage = (gainedValue / totalValue) * 100;
System.out.println(percentage);
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0