Skip to content
Permalink
Browse files

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

  • Loading branch information
opx3 committed Aug 20, 2016
1 parent bac4be9 commit f22fe982feb30c5566eb665b423a6bb2806ed022
@@ -1,18 +1,12 @@
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){
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.getDefault());
DecimalFormat twoDForm = new DecimalFormat("#"+decimalFormatSymbols.getDecimalSeparator()+"##",decimalFormatSymbols);
return Double.valueOf(twoDForm.format(iVal));
return (double)Math.round(iVal * 100) / 100;
}
}
@@ -18,5 +18,6 @@ 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 f22fe98

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