public class CurrencyValue extends Object implements Comparable<CurrencyValue>
Constructor and Description |
---|
CurrencyValue(long amount,
String currencyCode)
Constructs a new currency value.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(CurrencyValue o) |
static long |
convertAmount(double exchangeRate,
int sourceFractionDigits,
long sourceAmount,
int targetFractionDigits)
Performs a currency conversion & unit conversion.
|
static long |
convertAmount(double exchangeRate,
String sourceCurrencyCode,
long sourceAmount,
String targetCurrencyCode)
Performs a currency conversion & unit conversion.
|
static long |
convertAmount(ExchangeRateProvider exchangeRates,
String sourceCurrencyCode,
long sourceAmount,
String targetCurrencyCode)
Performs a currency conversion & unit conversion.
|
CurrencyValue |
convertTo(ExchangeRateProvider exchangeRates,
String targetCurrencyCode)
Returns a new CurrencyValue that is the conversion of this CurrencyValue to the specified currency.
|
long |
getAmount()
The amount of the CurrencyValue.
|
String |
getCurrencyCode()
The ISO currency code of the CurrencyValue.
|
static CurrencyValue |
parse(String externalVal,
String defaultCurrency)
Constructs a new currency value by parsing the specific input.
|
String |
strValue()
Returns a string representing the currency value such as "3.14,USD" for
a CurrencyValue of $3.14 USD.
|
String |
toString() |
public CurrencyValue(long amount, String currencyCode)
amount
- The amount.currencyCode
- The currency code.public static CurrencyValue parse(String externalVal, String defaultCurrency)
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.
externalVal
- The value to parse.defaultCurrency
- The default currency.public long getAmount()
public String getCurrencyCode()
public static long convertAmount(ExchangeRateProvider exchangeRates, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode)
exchangeRates
- Exchange rates to apply.sourceCurrencyCode
- The source currency code.sourceAmount
- The source amount.targetCurrencyCode
- The target currency code.public static long convertAmount(double exchangeRate, int sourceFractionDigits, long sourceAmount, int targetFractionDigits)
exchangeRate
- Exchange rate to apply.sourceFractionDigits
- The fraction digits of the source.sourceAmount
- The source amount.targetFractionDigits
- The fraction digits of the target.public static long convertAmount(double exchangeRate, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode)
exchangeRate
- Exchange rate to apply.sourceCurrencyCode
- The source currency code.sourceAmount
- The source amount.targetCurrencyCode
- The target currency code.public CurrencyValue convertTo(ExchangeRateProvider exchangeRates, String targetCurrencyCode)
exchangeRates
- The exchange rate provider.targetCurrencyCode
- The target currency code to convert this CurrencyValue to.public String strValue()
public int compareTo(CurrencyValue o)
compareTo
in interface Comparable<CurrencyValue>
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.