Skip to content
Permalink
Browse files

Revert "[JENKINS-37329] - Changed caluclation of RoundDecimal again."

This reverts commit f22fe98.
  • Loading branch information
opx3 committed Aug 20, 2016
1 parent f22fe98 commit b4486c4ae1a216e48029d36708c9fcb47be2f4f3
@@ -1,12 +1,18 @@
package jenkins.plugins.build_metrics.stats;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class StatsMath {

public static double getPercent(double subVal, double totalVal){
return roundTwoDecimals((totalVal == 0) ? 0.00 : (subVal / totalVal) * 100.00);
}

public static double roundTwoDecimals(double iVal){
return (double)Math.round(iVal * 100) / 100;
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.getDefault());
DecimalFormat twoDForm = new DecimalFormat("#"+decimalFormatSymbols.getDecimalSeparator()+"##",decimalFormatSymbols);
return Double.valueOf(twoDForm.format(iVal));
}
}
@@ -18,6 +18,5 @@ public void testPercent(){
assertEquals("2/3", 66.67, StatsMath.getPercent(subVal, totalVal), 0);
assertEquals("1/1", 100.00, StatsMath.getPercent(1, 1), 0);
assertEquals("3/2", 150.00, StatsMath.getPercent(3, 2), 0);
assertEquals("6/1", 16.67, StatsMath.getPercent(1, 6), 0);
}
}

0 comments on commit b4486c4

Please sign in to comment.
You can’t perform that action at this time.