Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "[JENKINS-37329] - Changed caluclation of RoundDecimal again."
This reverts commit f22fe98.
  • Loading branch information
opx3 committed Aug 20, 2016
1 parent f22fe98 commit b4486c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
@@ -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));
}
}
Expand Up @@ -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.