List of utility methods to do BigDecimal Round
BigDecimal | round(final BigDecimal input, final int precision) round final MathContext mc = new MathContext(precision + 1); return input.round(mc); |
BigDecimal | round(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode roundingMode) round if (number == null) { throw new NullPointerException("number"); if (roundingMode == null) { throw new NullPointerException("roundingMode"); if (minFractionDigits < 0) { throw new IllegalArgumentException( ... |
double | round_BigDecimal(double d, int decLen) roun Big Decimal BigDecimal bigD = new BigDecimal(d); if (decLen < 0) { double tempValue = bigD.movePointLeft(-decLen).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue(); bigD = (new BigDecimal(tempValue)).movePointRight(-decLen); } else { bigD = bigD.setScale(decLen, BigDecimal.ROUND_HALF_UP); return bigD.doubleValue(); ... |
BigDecimal | roundBigDecimal(BigDecimal num) round Big Decimal return roundBigDecimal(num, 2);
|
Number | roundBigDecimal(Number value, double precision) rounding with big decimal precision if (value != null) { BigDecimal val = value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString()); BigDecimal prec = BigDecimal.valueOf(precision); return val.divide(prec, BigDecimal.ROUND_HALF_EVEN).setScale(0, BigDecimal.ROUND_HALF_EVEN) .multiply(prec); return null; |
BigDecimal | roundCommercial(BigDecimal value, int decimalPlaces) round Commercial return value.round(getMathContext(decimalPlaces));
|
String | roundDecimal(Object value) round Decimal return roundDecimal(value, "###,###.##"); |
Float | roundDecimals(Float d) Round a float to decimal Float roundedFloat = null; if (d != null) { int nrdec = getNumberOfDecimalPlace(d); StringBuilder strbuf = new StringBuilder(); strbuf.append("#."); for (int i = 0; i < nrdec; i++) { strbuf.append("#"); DecimalFormat decformatter = decFormatMapCache.get(strbuf.toString()); if (decformatter == null) { decformatter = new DecimalFormat(strbuf.toString(), DECIMALSEP); decFormatMapCache.put(strbuf.toString(), decformatter); roundedFloat = Float.valueOf(decformatter.format(d)); return roundedFloat; |
BigDecimal | roundDoubleAsBigDecimal(double d, int numberOfDecimals) Rounds a double with the given number of decimals and returns a BigDecimal. BigDecimal bigDecimal = new BigDecimal(d).setScale(numberOfDecimals, BigDecimal.ROUND_HALF_UP); return bigDecimal; |
int | roundDown(BigDecimal a) round Down if (isZero(a)) { return 0; int i = a.intValue(); return i; |