public class Money extends BigDecimal
Combination of BigDecimal with Currency Sign
This class handles money amounts that include a currency signONE, ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UNNECESSARY, ROUND_UP, TEN, ZERO
Constructor and Description |
---|
Money(BigDecimal oVal,
CurrencyCode oCur)
Constructor
|
Money(BigDecimal oVal,
String sCur)
Constructor
|
Money(BigInteger oVal,
CurrencyCode oCur)
Constructor
|
Money(BigInteger oVal,
String sCur)
Constructor
|
Money(double dVal,
CurrencyCode oCur)
Constructor
|
Money(double dVal,
String sCur)
Constructor
|
Money(Money oVal)
Constructor that makes a copy from another Money value
|
Money(String sVal,
CurrencyCode oCur)
Constructor
|
Money(String sVal,
String sCur)
Constructor
|
Modifier and Type | Method and Description |
---|---|
Money |
add(Money oMny)
Add two money amounts
|
int |
compareTo(Money oMny)
Compare to money amounts with the same currency
|
Money |
convertTo(CurrencyCode oTarget,
BigDecimal oRatio)
Convert this money to another currency
|
Money |
convertTo(String sTarget,
BigDecimal oRatio)
Convert this money to another currency
|
CurrencyCode |
currencyCode() |
String |
format(String sLanguage,
String sCountry)
Format a BigDecimal as a String following the rules for an specific language and country
|
static boolean |
isMoney(String sVal)
Checks whether the given string can be parsed as a valid Money value
|
Money |
max(Money oMny)
Maximum of this Money instance and given Money instance
|
Money |
min(Money oMny)
Minimum of this Money instance and given Money instance
|
static Money |
parse(String sVal)
Create a Money instance from a figure and currency
|
Money |
round2()
Rounds a BigDecimal value to two decimals
|
Money |
subtract(Money oMny)
Subtract two money amounts
|
String |
toLocaleString() |
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, toString, ulp, unscaledValue, valueOf, valueOf, valueOf
byteValue, shortValue
public Money(Money oVal)
oVal
- Moneypublic Money(String sVal, CurrencyCode oCur) throws NumberFormatException
sVal
- String Numeric value in US decimal format (using dot as decimal delimiter)oCur
- CurrencyCodeNumberFormatException
public Money(String sVal, String sCur) throws NumberFormatException, IllegalArgumentException
sVal
- String Numeric value in US decimal format (using dot as decimal delimiter)sCur
- String Currency alphanumeric code {"USD", "EUR", etc.}NumberFormatException
IllegalArgumentException
public Money(double dVal, CurrencyCode oCur)
dVal
- doubleoCur
- CurrencyCodepublic Money(double dVal, String sCur) throws IllegalArgumentException
dVal
- doublesCur
- String Currency alphanumeric code {"USD", "EUR", etc.}IllegalArgumentException
- if currency code is not recognizedpublic Money(BigDecimal oVal, String sCur)
oVal
- BigDecimalsCur
- String Currency alphanumeric code {"USD", "EUR", etc.}IllegalArgumentException
- if currency code is not recognizedpublic Money(BigDecimal oVal, CurrencyCode oCur)
oVal
- BigDecimaloCur
- CurrencyCodepublic Money(BigInteger oVal, CurrencyCode oCur)
oVal
- BigIntegeroCur
- CurrencyCodepublic Money(BigInteger oVal, String sCur)
oVal
- BigIntegersCur
- String Currency alphanumeric code {"USD", "EUR", etc.}IllegalArgumentException
- if currency code is not recognizedpublic CurrencyCode currencyCode()
public int compareTo(Money oMny) throws IllegalArgumentException
oMny
- MoneyIllegalArgumentException
- If currency codes are not the samepublic Money max(Money oMny)
oMny
- Moneypublic Money min(Money oMny)
oMny
- Moneypublic Money add(Money oMny) throws NullPointerException, IllegalArgumentException
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()).NullPointerException
- If oMny is nullIllegalArgumentException
- If currency codes are not the samepublic Money subtract(Money oMny) throws 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()).NullPointerException
- If oMny is nullIllegalArgumentException
- If currency codes are not the samepublic static boolean isMoney(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 ignoredsVal
- Stringpublic static Money parse(String sVal) throws NullPointerException, IllegalArgumentException, NumberFormatException
Create a Money instance from a figure and currency
sVal
- String Must be of the form Currency Code + Figure or Figure + Currency Code. For example "23,5 EUR" or "GBP 12.8"
The figure may contain dot or comma as a decimal delimiter. € $ £ and ¥ are also recognized as currency codesNullPointerException
- If String parameter is nullIllegalArgumentException
- If String parameter is an empty StringNumberFormatException
public Money round2()
public Money convertTo(CurrencyCode oTarget, BigDecimal oRatio) throws NullPointerException
Convert this money to another currency
oTarget
- Target CurrencyCodeoRatio
- BigDecimal Conversion ratioNullPointerException
- if oTarget is nullpublic Money convertTo(String sTarget, BigDecimal oRatio) throws NullPointerException, IllegalArgumentException
Convert this money to another currency
sTarget
- Target CurrencyCodeoRatio
- BigDecimal Conversion ratioNullPointerException
- if oTarget is nullIllegalArgumentException
public String format(String sLanguage, String sCountry)
sLanguage
- String ISO-639 two letter language codesCountry
- String ISO-3166 two leter country codepublic String toLocaleString()
Copyright © 2001–2019 KnowGate. All rights reserved.