public class Money
extends java.math.BigDecimal
Combination of BigDecimal with Currency Sign
This class handles money amounts that include a currency signConstructor and Description |
---|
Money(java.math.BigDecimal oVal,
CurrencyCode oCur) |
Money(java.math.BigDecimal oVal,
java.lang.String sCur) |
Money(java.math.BigInteger oVal,
CurrencyCode oCur) |
Money(java.math.BigInteger oVal,
java.lang.String sCur) |
Money(double dVal,
CurrencyCode oCur)
Constructor
|
Money(double dVal,
java.lang.String sCur)
Constructor
|
Money(Money oVal)
Constructor that makes a copy from another Money value
|
Money(java.lang.String sVal,
CurrencyCode oCur)
Constructor
|
Money(java.lang.String sVal,
java.lang.String sCur)
Constructor
|
Modifier and Type | Method and Description |
---|---|
Money |
add(Money oMny)
Add two money amounts
The return value is in the currency of this object.
|
int |
compareTo(Money oMny) |
Money |
convertTo(CurrencyCode oTarget)
Convert this money to another currency using a web service for finding the conversion ratio
|
Money |
convertTo(CurrencyCode oTarget,
java.math.BigDecimal oRatio)
Convert this money to another currency
|
Money |
convertTo(java.lang.String sTarget)
Convert this money to another currency using a web service for finding the conversion ratio
|
Money |
convertTo(java.lang.String sTarget,
java.math.BigDecimal oRatio)
Convert this money to another currency
|
CurrencyCode |
currencyCode() |
java.lang.String |
format(java.lang.String sLanguage,
java.lang.String sCountry)
Format a BigDecimal as a String following the rules for an specific language and country
|
static boolean |
isMoney(java.lang.String sVal)
Checks whether the given string can be parsed as a valid Money value
Both comma and dot are allowed as either thousands or decimal delimiters.
|
Money |
max(Money oMny) |
Money |
min(Money oMny) |
static Money |
parse(java.lang.String sVal) |
Money |
round2()
Rounds a BigDecimal value to two decimals
|
Money |
subtract(Money oMny)
Subtract two money amounts
The return value is in the currency of this object.
|
java.lang.String |
toString() |
abs, abs, add, add, byteValueExact, compareTo, divide, divide, divide, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideToIntegralValue, divideToIntegralValue, doubleValue, equals, floatValue, hashCode, intValue, intValueExact, longValue, longValueExact, max, min, movePointLeft, movePointRight, multiply, multiply, negate, negate, plus, plus, pow, pow, precision, remainder, remainder, round, scale, scaleByPowerOfTen, setScale, setScale, setScale, shortValueExact, signum, stripTrailingZeros, subtract, subtract, toBigInteger, toBigIntegerExact, toEngineeringString, toPlainString, ulp, unscaledValue, valueOf, valueOf, valueOf
public Money(Money oVal)
public Money(java.lang.String sVal, CurrencyCode oCur) throws java.lang.NumberFormatException
sVal
- String Numeric value in US decimal format (using dot as decimal delimiter)oCur
- CurrencyCodejava.lang.NumberFormatException
public Money(java.lang.String sVal, java.lang.String sCur) throws java.lang.NumberFormatException, java.lang.IllegalArgumentException
sVal
- String Numeric value in US decimal format (using dot as decimal delimiter)sCur
- String Currency alphanumeric code {"USD", "EUR", etc.}java.lang.NumberFormatException
java.lang.IllegalArgumentException
public Money(double dVal, CurrencyCode oCur)
dVal
- doubleoCur
- CurrencyCodepublic Money(double dVal, java.lang.String sCur) throws java.lang.IllegalArgumentException
dVal
- doublesCur
- String Currency alphanumeric code {"USD", "EUR", etc.}java.lang.IllegalArgumentException
public Money(java.math.BigDecimal oVal, CurrencyCode oCur)
public Money(java.math.BigDecimal oVal, java.lang.String sCur)
public Money(java.math.BigInteger oVal, CurrencyCode oCur)
public Money(java.math.BigInteger oVal, java.lang.String sCur)
public CurrencyCode currencyCode()
public int compareTo(Money oMny)
public Money add(Money oMny) throws java.lang.NullPointerException
Add two money amounts
The return value is in the currency of this object. If the added amount does not have the same currency then it is converted by calling a web service before performing addition. The scale of the returned value is max(this.scale(), oMny.scale()).java.lang.NullPointerException
public Money subtract(Money oMny) throws java.lang.NullPointerException
Subtract two money amounts
The return value is in the currency of this object. If the added amount does not have the same currency then it is converted by calling a web service before performing addition. The scale of the returned value is max(this.scale(), oMny.scale()).java.lang.NullPointerException
public static boolean isMoney(java.lang.String sVal)
Checks whether the given string can be parsed as a valid Money value
Both comma and dot are allowed as either thousands or decimal delimiters. If there is only a comma or a dot then it is assumed to be de decimal delimiter. If both comma and dot are present, then the leftmost of them is assumed to be the thousands delimiter and the rightmost is the decimal delimiter. Any letters and currency symbols {€$£¤¢¥#ƒ&} are ignoredpublic static Money parse(java.lang.String sVal) throws java.lang.NullPointerException, java.lang.IllegalArgumentException, java.lang.NumberFormatException
java.lang.NullPointerException
java.lang.IllegalArgumentException
java.lang.NumberFormatException
public Money round2()
public Money convertTo(CurrencyCode oTarget, java.math.BigDecimal oRatio) throws java.lang.NullPointerException
Convert this money to another currency
oTarget
- Target CurrencyCodeoRatio
- BigDecimal Conversion ratiojava.lang.NullPointerException
- if oTarget is nullpublic Money convertTo(java.lang.String sTarget, java.math.BigDecimal oRatio) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
Convert this money to another currency
oTarget
- Target CurrencyCodeoRatio
- BigDecimal Conversion ratiojava.lang.NullPointerException
- if oTarget is nulljava.lang.IllegalArgumentException
public Money convertTo(CurrencyCode oTarget) throws java.lang.NullPointerException, java.lang.NumberFormatException
Convert this money to another currency using a web service for finding the conversion ratio
oTarget
- Target CurrencyCodejava.lang.NullPointerException
- if oTarget is nulljava.lang.NumberFormatException
public Money convertTo(java.lang.String sTarget) throws java.lang.NullPointerException, java.lang.NumberFormatException, java.lang.IllegalArgumentException
Convert this money to another currency using a web service for finding the conversion ratio
sTarget
- 3 letter Code of Target Currencyjava.lang.NullPointerException
- if oTarget is nulljava.lang.IllegalArgumentException
- if sTarget is not a valid currency codejava.lang.NumberFormatException
public java.lang.String format(java.lang.String sLanguage, java.lang.String sCountry)
sLanguage
- String ISO-639 two letter language codesCountry
- String ISO-3166 two leter country codepublic java.lang.String toString()
toString
in class java.math.BigDecimal