I am trying to calculate percentage for work using java. Here is the sample code,
public class WorkCalculaor {
public static void main(String[] args) {
WorkCalculaor wc = new WorkCalculaor();
System.out.println(wc.calculateWork(50, 40)); // should be 120%
System.out.println(wc.calculateWork(60, 100)); // should be 33.33%
}
public double calculateWork(double target, double actual) {
//work = [100 + ((Target – Actual) /Target)*100 ] %
double work = (target - actual);
work = work/target;
work = work*100;
work = 100 + work;
return work;
}
}
My actual requirement is ,i wil have actual minutes and target minutes as input and then i need to calculate below percatage on those target and actual minutes.
[100 + ((Target – Actual) /Target)*100 ] %
I mean percentage calculation.
SO, if i give calculateWork(50, 40) i should get 120% and if i give calculateWork(60, 100) i should get 33.33%.
I have written the above code and its working fine. Is this is the right approach?
Also only 2 decimals of percantage value is needed.
can anyone suggest?
Thanks.