Java BigDecimal Round rounded(BigDecimal amount)

Here you can find the source of rounded(BigDecimal amount)

Description

Rounds an amount to two decimal places.

License

Open Source License

Parameter

Parameter Description
amount the amount to round, not null

Return

the rounded amount, not null

Declaration

public static BigDecimal rounded(BigDecimal amount) 

Method Source Code

//package com.java2s;
/**//from  ww w  . j a va2 s. com
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */

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

public class Main {
    /**
     * The number of decimals to retain.
     */
    public static final int DECIMALS = 2;
    /**
     * The rounding mode.
     */
    public static final RoundingMode ROUNDING_MODE = RoundingMode.HALF_EVEN;

    /**
     * Rounds an amount to two decimal places.
     * 
     * @param amount  the amount to round, not null
     * @return the rounded amount, not null
     */
    public static BigDecimal rounded(BigDecimal amount) {
        return amount.setScale(DECIMALS, ROUNDING_MODE);
    }
}

Related

  1. roundCommercial(BigDecimal value, int decimalPlaces)
  2. roundDecimal(Object value)
  3. roundDecimals(Float d)
  4. roundDoubleAsBigDecimal(double d, int numberOfDecimals)
  5. roundDown(BigDecimal a)
  6. roundHalfUp2Scale(BigDecimal value)
  7. roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode)
  8. roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode)
  9. roundOff(final BigDecimal amount)