Java BigDecimal Round getRoundedBigDecimal(double value)

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

Description

Get a big decimal rounded out to NUMBER_DECIMAL_PLACES places from the supplied double.

License

Apache License

Parameter

Parameter Description
value a parameter

Declaration

public static BigDecimal getRoundedBigDecimal(double value) 

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;

    /**/*w  w w .  j  a va  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, int scale)
  6. getStringValue(BigDecimal val, int newScale, int roundingMode)
  7. magicRound(BigDecimal value)
  8. round(BigDecimal amount)