Java BigDecimal Round decimalRound(BigDecimal number, int numDigits, RoundingMode rounding)

Here you can find the source of decimalRound(BigDecimal number, int numDigits, RoundingMode rounding)

Description

Rounding for decimals with support for negative digits

License

Open Source License

Declaration

public static BigDecimal decimalRound(BigDecimal number, int numDigits, RoundingMode rounding) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    /**//ww w .  ja va 2 s.  c o  m
     * Rounding for decimals with support for negative digits
     */
    public static BigDecimal decimalRound(BigDecimal number, int numDigits, RoundingMode rounding) {
        BigDecimal rounded = number.setScale(numDigits, rounding);

        if (numDigits < 0) {
            rounded = rounded.setScale(0, BigDecimal.ROUND_UNNECESSARY);
        }

        return rounded;
    }
}

Related

  1. average(int precision, RoundingMode roundingMode, BigDecimal... decimals)
  2. getEfficientRound(BigDecimal val, int effectiveDigit)
  3. getRoundedAmt(BigDecimal amtBeforeRnd)
  4. getRoundedBigDecimal(double value)
  5. getRoundedBigDecimal(double value, int scale)