Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

The list of methods to do BigDecimal are organized into topic(s).

Method

intgetLocalHourMinute(BigDecimal gmtHour)
get Local Hour Minute
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.clear();
int hour = gmtHour.intValue();
c.set(Calendar.HOUR_OF_DAY, hour);
Date t = c.getTime();
c = Calendar.getInstance();
c.setTime(t);
int localHour = c.get(Calendar.HOUR_OF_DAY);
...
BigDecimalgetMaxBigDecimal(@Nonnull final BigDecimal aValue, @Nonnull final BigDecimal... aValues)
get Max Big Decimal
BigDecimal ret = aValue;
for (final BigDecimal a : aValues)
    if (a.compareTo(ret) > 0)
        ret = a;
return ret;
BigDecimalgetMaxBigDecimal(int precision, int scale)
get Max Big Decimal
BigDecimal fraction = BigDecimal.ONE.subtract(BigDecimal.ONE.divide(BigDecimal.TEN.pow(scale)));
BigDecimal whole = BigDecimal.TEN.pow(precision - scale).subtract(BigDecimal.ONE);
return whole.add(fraction);
intgetMaxPrecision(BigDecimal... decimals)
Returns the maximum precision used by the given list of decimals.
int precision = DEFAULT_DECIMAL_PRECISION;
if (decimals != null) {
    for (BigDecimal decimal : decimals) {
        if (decimal != null && decimal.scale() > precision)
            precision = decimal.scale();
return precision;
...
BigDecimalgetMean(final BigDecimal... vals)
get Mean
int count = 0;
BigDecimal sum = new BigDecimal(0);
for (final BigDecimal d : vals) {
    if (d == null) {
        continue;
    sum = sum.add(d);
    count++;
...
longgetMicroSec(BigDecimal hours)
get Micro Sec
BigDecimal bd;
bd = hours.multiply(new BigDecimal(3600 * 1000));
return bd.longValue();
BigDecimalgetNumberAsBigDecimal(Number value)
get Number As Big Decimal
if (value == null)
    return null;
return new BigDecimal(String.valueOf(value));
intgetNumberOfDecimalPlaces(BigDecimal bigDecimal)
get Number Of Decimal Places
String string = bigDecimal.stripTrailingZeros().toPlainString();
int index = string.indexOf(".");
return index < 0 ? 0 : string.length() - index - 1;
BigDecimalgetParamBigDecimal(Map paramMap, String paramName)
get Param Big Decimal
String[] paramArr = paramMap.get(paramName);
if (paramArr == null || paramArr.length == 0)
    return null;
try {
    return new BigDecimal(paramArr[0]);
} catch (Exception e) {
    return null;
BigDecimalgetPercent(BigDecimal numerator, BigDecimal denominator)
get Percent
if (denominator == null || numerator == null || denominator.compareTo(BigDecimal.ZERO) == 0) {
    return BigDecimal.ZERO;
return numerator.divide(denominator, 4, BigDecimal.ROUND_HALF_EVEN).multiply(HUNDRED).setScale(2,
        BigDecimal.ROUND_HALF_EVEN);