arabian_albert arabian_albert - 1 month ago 9
Java Question

Calculate percent difference

I have 2 doubles.

double a = 100.00
double b = 99.00


The difference here is that b exhibits a 1% decrease with respect to a.

How can I calculate something similar in Java?

Answer
double percDiff = Math.abs( a - b ) / a * 100;

or if you want sign

double percDiff = (b - a) / a * 100;