[New] Added MathHelper.getNumberOfDecimalPlaces()

This commit is contained in:
Robert von Burg 2020-07-06 12:57:00 +02:00
parent 626fb847f7
commit 3cd63ff7cd
1 changed files with 8 additions and 0 deletions

View File

@ -127,4 +127,12 @@ public class MathHelper {
return "" + Double.POSITIVE_INFINITY;
return String.valueOf(BigDecimal.valueOf(value).setScale(decimals, RoundingMode.HALF_EVEN).doubleValue());
}
public static int getNumberOfDecimalPlaces(double value) {
return getNumberOfDecimalPlaces(BigDecimal.valueOf(value));
}
public static int getNumberOfDecimalPlaces(BigDecimal bigDecimal) {
return Math.max(0, bigDecimal.stripTrailingZeros().scale());
}
}