Here you can find the source of subtract(final BigDecimal baseAmount, final BigDecimal amountToSubtract)
Parameter | Description |
---|---|
baseAmount | the amount to subtract from, not null |
amountToSubtract | the amount to subtract, not null |
public static BigDecimal subtract(final BigDecimal baseAmount, final BigDecimal amountToSubtract)
//package com.java2s; /**/*w ww . jav a 2 s. c om*/ * 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; /** * Subtract one amount from another rounding to two decimal places. * * @param baseAmount the amount to subtract from, not null * @param amountToSubtract the amount to subtract, not null * @return the subtraction result, not null */ public static BigDecimal subtract(final BigDecimal baseAmount, final BigDecimal amountToSubtract) { return rounded(baseAmount).subtract(rounded(amountToSubtract)); } /** * 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); } }