Java BigDecimal Round getRoundedBigDecimal(double value, int scale)

Here you can find the source of getRoundedBigDecimal(double value, int scale)

Description

get Rounded Big Decimal

License

Apache License

Declaration

public static BigDecimal getRoundedBigDecimal(double value, int scale) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static final int NUMBER_DECIMAL_PLACES = 4;

    public static BigDecimal getRoundedBigDecimal(double value, int scale) {
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(scale, RoundingMode.HALF_UP);

        return bd;
    }//from w w  w  .  j  av a 2  s  .  c  o  m

    /**
     * Get a big decimal rounded out to NUMBER_DECIMAL_PLACES places
     * from the supplied double.
     * 
     * @param value
     * @return
     */
    public static BigDecimal getRoundedBigDecimal(double value) {
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(NUMBER_DECIMAL_PLACES, RoundingMode.HALF_UP);

        return bd;
    }
}

Related

  1. average(int precision, RoundingMode roundingMode, BigDecimal... decimals)
  2. decimalRound(BigDecimal number, int numDigits, RoundingMode rounding)
  3. getEfficientRound(BigDecimal val, int effectiveDigit)
  4. getRoundedAmt(BigDecimal amtBeforeRnd)
  5. getRoundedBigDecimal(double value)
  6. getStringValue(BigDecimal val, int newScale, int roundingMode)
  7. magicRound(BigDecimal value)
  8. round(BigDecimal amount)
  9. round(BigDecimal aValue, int aScale)