Here you can find the source of add(final BigDecimal baseAmount, final BigDecimal amountToAdd)
Parameter | Description |
---|---|
baseAmount | the base amount, not null |
amountToAdd | the amount to add, not null |
public static BigDecimal add(final BigDecimal baseAmount, final BigDecimal amountToAdd)
//package com.java2s; /**// ww w . j a va 2s . co m * 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; /** * Adds two amounts rounding to two decimal places. * * @param baseAmount the base amount, not null * @param amountToAdd the amount to add, not null * @return the total, not null */ public static BigDecimal add(final BigDecimal baseAmount, final BigDecimal amountToAdd) { return rounded(baseAmount).add(rounded(amountToAdd)); } /** * 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); } }