Class CurrencyValue

    • Constructor Detail

      • CurrencyValue

        public CurrencyValue​(long amount,
                             String currencyCode)
        Constructs a new currency value.
        Parameters:
        amount - The amount.
        currencyCode - The currency code.
    • Method Detail

      • parse

        public static CurrencyValue parse​(String externalVal,
                                          String defaultCurrency)
        Constructs a new currency value by parsing the specific input.

        Currency values are expected to be in the format <amount>,<currency code>, for example, "500,USD" would represent 5 U.S. Dollars.

        If no currency code is specified, the default is assumed.

        Parameters:
        externalVal - The value to parse.
        defaultCurrency - The default currency.
        Returns:
        The parsed CurrencyValue.
      • getAmount

        public long getAmount()
        The amount of the CurrencyValue.
        Returns:
        The amount.
      • getCurrencyCode

        public String getCurrencyCode()
        The ISO currency code of the CurrencyValue.
        Returns:
        The currency code.
      • convertAmount

        public static long convertAmount​(ExchangeRateProvider exchangeRates,
                                         String sourceCurrencyCode,
                                         long sourceAmount,
                                         String targetCurrencyCode)
        Performs a currency conversion & unit conversion.
        Parameters:
        exchangeRates - Exchange rates to apply.
        sourceCurrencyCode - The source currency code.
        sourceAmount - The source amount.
        targetCurrencyCode - The target currency code.
        Returns:
        The converted indexable units after the exchange rate and currency fraction digits are applied.
      • convertAmount

        public static long convertAmount​(double exchangeRate,
                                         int sourceFractionDigits,
                                         long sourceAmount,
                                         int targetFractionDigits)
        Performs a currency conversion & unit conversion.
        Parameters:
        exchangeRate - Exchange rate to apply.
        sourceFractionDigits - The fraction digits of the source.
        sourceAmount - The source amount.
        targetFractionDigits - The fraction digits of the target.
        Returns:
        The converted indexable units after the exchange rate and currency fraction digits are applied.
      • convertAmount

        public static long convertAmount​(double exchangeRate,
                                         String sourceCurrencyCode,
                                         long sourceAmount,
                                         String targetCurrencyCode)
        Performs a currency conversion & unit conversion.
        Parameters:
        exchangeRate - Exchange rate to apply.
        sourceCurrencyCode - The source currency code.
        sourceAmount - The source amount.
        targetCurrencyCode - The target currency code.
        Returns:
        The converted indexable units after the exchange rate and currency fraction digits are applied.
      • convertTo

        public CurrencyValue convertTo​(ExchangeRateProvider exchangeRates,
                                       String targetCurrencyCode)
        Returns a new CurrencyValue that is the conversion of this CurrencyValue to the specified currency.
        Parameters:
        exchangeRates - The exchange rate provider.
        targetCurrencyCode - The target currency code to convert this CurrencyValue to.
        Returns:
        The converted CurrencyValue.
      • strValue

        public String strValue()
        Returns a string representing the currency value such as "3.14,USD" for a CurrencyValue of $3.14 USD.