Skip to content

Commit

Permalink
#1739 fix usage of setScale
Browse files Browse the repository at this point in the history
  • Loading branch information
steveswinsburg committed Feb 17, 2016
1 parent 3015b84 commit cca6ca2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ public static String formatDoubleAsPercentage(final Double score) {
return formatDoubleToTwoDecimalPlaces(score) + "%";
}

/**
* Format the given string as a percentage with two decimal precision. String should be something that can be converted to a number.
*
* @param string string representation of the number
* @return percentage to decimal places with a '%' for good measure
*/
public static String formatStringAsPercentage(final String string) {
if (StringUtils.isBlank(string)) {
return null;
}

final BigDecimal decimal = new BigDecimal(string);
decimal.setScale(2, RoundingMode.HALF_DOWN); // same as GradebookService
final BigDecimal decimal = new BigDecimal(string).setScale(2, RoundingMode.HALF_DOWN);

return formatDoubleAsPercentage(decimal.doubleValue());
}
Expand Down

0 comments on commit cca6ca2

Please sign in to comment.