Class BroadleafCurrencyUtils

java.lang.Object
org.broadleafcommerce.common.currency.util.BroadleafCurrencyUtils

public class BroadleafCurrencyUtils extends Object
Utility methods for common currency operations
Author:
Phillip Verheyden
  • Field Details

    • ROUND_FLOOR_MATH_CONTEXT

      public static final MathContext ROUND_FLOOR_MATH_CONTEXT
    • FORMAT_CACHE

      protected static final Map<String,NumberFormat> FORMAT_CACHE
  • Constructor Details

    • BroadleafCurrencyUtils

      public BroadleafCurrencyUtils()
  • Method Details

    • getMoney

      public static Money getMoney(BigDecimal amount, BroadleafCurrency currency)
    • getMoney

      public static Money getMoney(BigDecimal amount)
    • getMoney

      public static Money getMoney(BroadleafCurrency currency)
    • getCurrency

      public static Currency getCurrency(Money money)
    • getCurrency

      public static Currency getCurrency(BroadleafCurrency currency)
    • getUnitAmount

      public static Money getUnitAmount(Money difference)
      Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
      Parameters:
      difference -
      Returns:
    • getUnitAmount

      public static Money getUnitAmount(BroadleafCurrency blCurrency)
      Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
      Parameters:
      blCurrency -
      Returns:
    • calculateRemainder

      public static 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).
      Parameters:
      totalAmount -
      quantity -
      Returns:
    • getNumberFormatFromCache

      public static NumberFormat getNumberFormatFromCache(Locale locale, Currency currency)
      Provides a cached approach for creating NumberFormat instances. More performant than creating a new one each time.
      Parameters:
      locale - the Locale
      currency - the Currency
      Returns:
      either a new NumberFormat instance, or one taken from the cache
    • getNumberFormatFromCache

      public static NumberFormat getNumberFormatFromCache(Locale locale, Currency currency, Map<String,String> localeToChange)