Class MonetaryAmountRoundingHelper
java.lang.Object
com.broadleafcommerce.paymenttransaction.service.utils.MonetaryAmountRoundingHelper
Helper class to calculate rounding of monetary unit amounts.
- Author:
- Marie Standeven (marieStandeven)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected javax.money.MonetaryAmount
getUnitAmount
(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.
-
Constructor Details
-
MonetaryAmountRoundingHelper
public MonetaryAmountRoundingHelper()
-
-
Method Details
-
roundListOfMonetaryAmounts
public Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amount
-
roundListOfMonetaryAmounts
protected Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amountunitAmount
- the smallest unit amount of money for the currency
-
getUnitAmount
protected javax.money.MonetaryAmount getUnitAmount(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.For example, a currency with 2 fraction digits (like USD) will provide the amount "0.01".
- Parameters:
currency
- the currency to get the smallest unit amount for- Returns:
- the smallest unit amount of money for the currency
-