List of utility methods to do BigDecimal
int | getLocalHourMinute(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); ... |
BigDecimal | getMaxBigDecimal(@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; |
BigDecimal | getMaxBigDecimal(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);
|
int | getMaxPrecision(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; ... |
BigDecimal | getMean(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++; ... |
long | getMicroSec(BigDecimal hours) get Micro Sec BigDecimal bd; bd = hours.multiply(new BigDecimal(3600 * 1000)); return bd.longValue(); |
BigDecimal | getNumberAsBigDecimal(Number value) get Number As Big Decimal if (value == null) return null; return new BigDecimal(String.valueOf(value)); |
int | getNumberOfDecimalPlaces(BigDecimal bigDecimal) get Number Of Decimal Places String string = bigDecimal.stripTrailingZeros().toPlainString(); int index = string.indexOf("."); return index < 0 ? 0 : string.length() - index - 1; |
BigDecimal | getParamBigDecimal(Map 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; |
BigDecimal | getPercent(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); |