Class BroadleafCurrencyUtils
java.lang.Object
org.broadleafcommerce.common.currency.util.BroadleafCurrencyUtils
Utility methods for common currency operations
- Author:
- Phillip Verheyden
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Map<String,
NumberFormat> static final MathContext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
calculateRemainder
(Money totalAmount, int quantity) Returns the remainder amount if the passed in totalAmount was divided by the quantity taking into account the normal unit of the currency (e.g. .01 for US).static Currency
getCurrency
(BroadleafCurrency currency) static Currency
getCurrency
(Money money) static Money
getMoney
(BigDecimal amount) static Money
getMoney
(BigDecimal amount, BroadleafCurrency currency) static Money
getMoney
(BroadleafCurrency currency) static NumberFormat
getNumberFormatFromCache
(Locale locale, Currency currency) Provides a cached approach for creating NumberFormat instances.static NumberFormat
static Money
getUnitAmount
(BroadleafCurrency blCurrency) Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)static Money
getUnitAmount
(Money difference) Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
-
Field Details
-
ROUND_FLOOR_MATH_CONTEXT
-
FORMAT_CACHE
-
-
Constructor Details
-
BroadleafCurrencyUtils
public BroadleafCurrencyUtils()
-
-
Method Details
-
getMoney
-
getMoney
-
getMoney
-
getCurrency
-
getCurrency
-
getUnitAmount
Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)- Parameters:
difference
-- Returns:
-
getUnitAmount
Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)- Parameters:
blCurrency
-- Returns:
-
calculateRemainder
Returns the remainder amount if the passed in totalAmount was divided by the quantity taking into account the normal unit of the currency (e.g. .01 for US).- Parameters:
totalAmount
-quantity
-- Returns:
-
getNumberFormatFromCache
Provides a cached approach for creating NumberFormat instances. More performant than creating a new one each time.- Parameters:
locale
- the Localecurrency
- the Currency- Returns:
- either a new NumberFormat instance, or one taken from the cache
-
getNumberFormatFromCache
-