public final class BigMoney extends Object implements BigMoneyProvider, Comparable<BigMoneyProvider>, Serializable
This class represents a quantity of money, stored as a BigDecimal
amount
in a single currency
.
Every currency has a certain standard number of decimal places.
This is typically 2 (Euro, British Pound, US Dollar) but might be
0 (Japanese Yen), 1 (Vietnamese Dong) or 3 (Bahrain Dinar).
The BigMoney
class is not restricted to the standard decimal places
and can represent an amount to any precision that a BigDecimal
can represent.
This class is immutable and threadsafe.
Modifier and Type  Method and Description 

BigMoney 
abs()
Returns a copy of this monetary value with a positive amount.

int 
compareTo(BigMoneyProvider other)
Compares this monetary value to another.

BigMoney 
convertedTo(CurrencyUnit currency,
BigDecimal conversionMultipler)
Returns a copy of this monetary value converted into another currency
using the specified conversion rate.

BigMoney 
convertRetainScale(CurrencyUnit currency,
BigDecimal conversionMultipler,
RoundingMode roundingMode)
Returns a copy of this monetary value converted into another currency
using the specified conversion rate, with a rounding mode used to adjust
the decimal places in the result.

BigMoney 
dividedBy(BigDecimal valueToDivideBy,
RoundingMode roundingMode)
Returns a copy of this monetary value divided by the specified value
using the specified rounding mode to adjust the scale.

BigMoney 
dividedBy(double valueToDivideBy,
RoundingMode roundingMode)
Returns a copy of this monetary value divided by the specified value
using the specified rounding mode to adjust the scale.

BigMoney 
dividedBy(long valueToDivideBy,
RoundingMode roundingMode)
Returns a copy of this monetary value divided by the specified value
using the specified rounding mode to adjust the decimal places in the result.

boolean 
equals(Object other)
Checks if this monetary value equals another.

BigDecimal 
getAmount()
Gets the amount.

BigDecimal 
getAmountMajor()
Gets the amount in major units as a
BigDecimal with scale 0. 
int 
getAmountMajorInt()
Gets the amount in major units as an
int . 
long 
getAmountMajorLong()
Gets the amount in major units as a
long . 
BigDecimal 
getAmountMinor()
Gets the amount in minor units as a
BigDecimal with scale 0. 
int 
getAmountMinorInt()
Gets the amount in minor units as an
int . 
long 
getAmountMinorLong()
Gets the amount in minor units as a
long . 
CurrencyUnit 
getCurrencyUnit()
Gets the currency.

int 
getMinorPart()
Gets the minor part of the amount.

int 
getScale()
Gets the scale of the
BigDecimal amount. 
int 
hashCode()
Returns a hash code for this monetary value.

boolean 
isCurrencyScale()
Checks if this money has the scale of the currency.

boolean 
isEqual(BigMoneyProvider other)
Checks if this monetary value is equal to another.

boolean 
isGreaterThan(BigMoneyProvider other)
Checks if this monetary value is greater than another.

boolean 
isLessThan(BigMoneyProvider other)
Checks if this monetary value is less than another.

boolean 
isNegative()
Checks if the amount is less than zero.

boolean 
isNegativeOrZero()
Checks if the amount is zero or less.

boolean 
isPositive()
Checks if the amount is greater than zero.

boolean 
isPositiveOrZero()
Checks if the amount is zero or greater.

boolean 
isSameCurrency(BigMoneyProvider money)
Checks if this instance and the specified instance have the same currency.

boolean 
isZero()
Checks if the amount is zero.

BigMoney 
minus(BigDecimal amountToSubtract)
Returns a copy of this monetary value with the amount subtracted.

BigMoney 
minus(BigMoneyProvider moneyToSubtract)
Returns a copy of this monetary value with the amount subtracted.

BigMoney 
minus(double amountToSubtract)
Returns a copy of this monetary value with the amount subtracted.

BigMoney 
minus(Iterable<? extends BigMoneyProvider> moniesToSubtract)
Returns a copy of this monetary value with a collection of monetary amounts subtracted.

BigMoney 
minusMajor(long amountToSubtract)
Returns a copy of this monetary value with the amount in major units subtracted.

BigMoney 
minusMinor(long amountToSubtract)
Returns a copy of this monetary value with the amount in minor units subtracted.

BigMoney 
minusRetainScale(BigDecimal amountToSubtract,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount subtracted retaining
the scale by rounding the result.

BigMoney 
minusRetainScale(BigMoneyProvider moneyToSubtract,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount in the same currency subtracted
retaining the scale by rounding the result.

BigMoney 
minusRetainScale(double amountToSubtract,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount subtracted retaining
the scale by rounding the result.

BigMoney 
multipliedBy(BigDecimal valueToMultiplyBy)
Returns a copy of this monetary value multiplied by the specified value.

BigMoney 
multipliedBy(double valueToMultiplyBy)
Returns a copy of this monetary value multiplied by the specified value.

BigMoney 
multipliedBy(long valueToMultiplyBy)
Returns a copy of this monetary value multiplied by the specified value.

BigMoney 
multiplyRetainScale(BigDecimal valueToMultiplyBy,
RoundingMode roundingMode)
Returns a copy of this monetary value multiplied by the specified value
using the specified rounding mode to adjust the scale of the result.

BigMoney 
multiplyRetainScale(double valueToMultiplyBy,
RoundingMode roundingMode)
Returns a copy of this monetary value multiplied by the specified value
using the specified rounding mode to adjust the scale of the result.

BigMoney 
negated()
Returns a copy of this monetary value with the amount negated.

static BigMoney 
nonNull(BigMoney money,
CurrencyUnit currency)
Ensures that a
BigMoney is not null . 
static BigMoney 
of(BigMoneyProvider moneyProvider)
Obtains an instance of
BigMoney from a provider. 
static BigMoney 
of(CurrencyUnit currency,
BigDecimal amount)
Obtains an instance of
BigMoney from a BigDecimal . 
static BigMoney 
of(CurrencyUnit currency,
double amount)
Obtains an instance of
BigMoney from a double using a welldefined conversion. 
static BigMoney 
ofMajor(CurrencyUnit currency,
long amountMajor)
Obtains an instance of
BigMoney from an amount in major units. 
static BigMoney 
ofMinor(CurrencyUnit currency,
long amountMinor)
Obtains an instance of
BigMoney from an amount in minor units. 
static BigMoney 
ofScale(CurrencyUnit currency,
BigDecimal amount,
int scale)
Obtains an instance of
BigMoney from a BigDecimal at a specific scale. 
static BigMoney 
ofScale(CurrencyUnit currency,
BigDecimal amount,
int scale,
RoundingMode roundingMode)
Obtains an instance of
BigMoney from a double using a
welldefined conversion, rounding as necessary. 
static BigMoney 
ofScale(CurrencyUnit currency,
long unscaledAmount,
int scale)
Obtains an instance of
BigMoney from a scaled amount. 
static BigMoney 
parse(String moneyStr)
Parses an instance of
BigMoney from a string. 
BigMoney 
plus(BigDecimal amountToAdd)
Returns a copy of this monetary value with the amount added.

BigMoney 
plus(BigMoneyProvider moneyToAdd)
Returns a copy of this monetary value with the amount added.

BigMoney 
plus(double amountToAdd)
Returns a copy of this monetary value with the amount added.

BigMoney 
plus(Iterable<? extends BigMoneyProvider> moniesToAdd)
Returns a copy of this monetary value with a collection of monetary amounts added.

BigMoney 
plusMajor(long amountToAdd)
Returns a copy of this monetary value with the amount in major units added.

BigMoney 
plusMinor(long amountToAdd)
Returns a copy of this monetary value with the amount in minor units added.

BigMoney 
plusRetainScale(BigDecimal amountToAdd,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount added retaining
the scale by rounding the result.

BigMoney 
plusRetainScale(BigMoneyProvider moneyToAdd,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount in the same currency added
retaining the scale by rounding the result.

BigMoney 
plusRetainScale(double amountToAdd,
RoundingMode roundingMode)
Returns a copy of this monetary value with the amount added retaining
the scale by rounding the result.

BigMoney 
rounded(int scale,
RoundingMode roundingMode)
Returns a copy of this monetary value rounded to the specified scale without
changing the current scale.

BigMoney 
toBigMoney()
Implements the
BigMoneyProvider interface, trivially
returning this . 
Money 
toMoney()
Converts this money to an instance of
Money without rounding. 
Money 
toMoney(RoundingMode roundingMode)
Converts this money to an instance of
Money . 
String 
toString()
Gets this monetary value as a string.

static BigMoney 
total(BigMoneyProvider... monies)
Obtains an instance of
BigMoney as the total value of an array. 
static BigMoney 
total(CurrencyUnit currency,
BigMoneyProvider... monies)
Obtains an instance of
Money as the total value of
a possibly empty array. 
static BigMoney 
total(CurrencyUnit currency,
Iterable<? extends BigMoneyProvider> monies)
Obtains an instance of
Money as the total value of
a possibly empty collection. 
static BigMoney 
total(Iterable<? extends BigMoneyProvider> monies)
Obtains an instance of
BigMoney as the total value of a collection. 
BigMoney 
withAmount(BigDecimal amount)
Returns a copy of this monetary value with the specified amount.

BigMoney 
withAmount(double amount)
Returns a copy of this monetary value with the specified amount using a welldefined
conversion from a
double . 
BigMoney 
withCurrencyScale()
Returns a copy of this monetary value with the scale of the currency,
truncating the amount if necessary.

BigMoney 
withCurrencyScale(RoundingMode roundingMode)
Returns a copy of this monetary value with the scale of the currency,
using the specified rounding mode if necessary.

BigMoney 
withCurrencyUnit(CurrencyUnit currency)
Returns a copy of this monetary value with the specified currency.

BigMoney 
withScale(int scale)
Returns a copy of this monetary value with the specified scale,
truncating the amount if necessary.

BigMoney 
withScale(int scale,
RoundingMode roundingMode)
Returns a copy of this monetary value with the specified scale,
using the specified rounding mode if necessary.

static BigMoney 
zero(CurrencyUnit currency)
Obtains an instance of
BigMoney representing zero. 
static BigMoney 
zero(CurrencyUnit currency,
int scale)
Obtains an instance of
BigMoney representing zero at a specific scale. 
public static BigMoney of(CurrencyUnit currency, BigDecimal amount)
BigMoney
from a BigDecimal
.
This allows you to create an instance with a specific currency and amount.
The scale of the money will be that of the BigDecimal
, with
a minimum scale of zero.
currency
 the currency, not nullamount
 the amount of money, not nullIllegalArgumentException
 if an invalid BigDecimal subclass has been usedpublic static BigMoney of(CurrencyUnit currency, double amount)
BigMoney
from a double
using a welldefined conversion.
This allows you to create an instance with a specific currency and amount.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.425d' will be converted to '1.425'.
The scale of the money will be that of the BigDecimal produced, with trailing zeroes stripped,
and with a minimum scale of zero.
currency
 the currency, not nullamount
 the amount of money, not nullpublic static BigMoney ofScale(CurrencyUnit currency, BigDecimal amount, int scale)
BigMoney
from a BigDecimal
at a specific scale.
This allows you to create an instance with a specific currency and amount. No rounding is performed on the amount, so it must have a scale less than or equal to the new scale. The result will have a minimum scale of zero.
currency
 the currency, not nullamount
 the amount of money, not nullscale
 the scale to use, zero or positiveArithmeticException
 if the scale exceeds the currency scalepublic static BigMoney ofScale(CurrencyUnit currency, BigDecimal amount, int scale, RoundingMode roundingMode)
BigMoney
from a double
using a
welldefined conversion, rounding as necessary.
This allows you to create an instance with a specific currency and amount. If the amount has a scale in excess of the scale of the currency then the excess fractional digits are rounded using the rounding mode. The result will have a minimum scale of zero.
currency
 the currency, not nullamount
 the amount of money, not nullscale
 the scale to use, zero or positiveroundingMode
 the rounding mode to use, not nullArithmeticException
 if the rounding failspublic static BigMoney ofScale(CurrencyUnit currency, long unscaledAmount, int scale)
BigMoney
from a scaled amount.
This allows you to create an instance with a specific currency, amount and scale. The amount is defined in terms of the specified scale. The result will have a minimum scale of zero.
For example, ofScale(USD, 234, 2)
creates the instance USD 2.34
.
currency
 the currency, not nullunscaledAmount
 the unscaled amount of moneyscale
 the scale to usepublic static BigMoney ofMajor(CurrencyUnit currency, long amountMajor)
BigMoney
from an amount in major units.
This allows you to create an instance with a specific currency and amount. The scale of the money will be zero.
The amount is a whole number only. Thus you can initialise the value
'USD 20', but not the value 'USD 20.32'.
For example, ofMajor(USD, 25)
creates the instance USD 25
.
currency
 the currency, not nullamountMajor
 the amount of money in the major division of the currencypublic static BigMoney ofMinor(CurrencyUnit currency, long amountMinor)
BigMoney
from an amount in minor units.
This allows you to create an instance with a specific currency and amount expressed in terms of the minor unit. The scale of the money will be that of the currency, such as 2 for USD or 0 for JPY.
For example, if constructing US Dollars, the input to this method represents cents.
Note that when a currency has zero decimal places, the major and minor units are the same.
For example, ofMinor(USD, 2595)
creates the instance USD 25.95
.
currency
 the currency, not nullamountMinor
 the amount of money in the minor division of the currencypublic static BigMoney zero(CurrencyUnit currency)
BigMoney
representing zero.
The scale of the money will be zero.
For example, zero(USD)
creates the instance USD 0
.
currency
 the currency, not nullpublic static BigMoney zero(CurrencyUnit currency, int scale)
BigMoney
representing zero at a specific scale.
For example, zero(USD, 2)
creates the instance USD 0.00
.
currency
 the currency, not nullscale
 the scale to use, zero or positiveIllegalArgumentException
 if the scale is negativepublic static BigMoney of(BigMoneyProvider moneyProvider)
BigMoney
from a provider.
This allows you to create an instance from any class that implements the
provider, such as Money
.
This method simply calls BigMoneyProvider.toBigMoney()
checking for nulls.
moneyProvider
 the money to convert, not nullpublic static BigMoney total(BigMoneyProvider... monies)
BigMoney
as the total value of an array.
The array must contain at least one monetary value.
Subsequent amounts are added as though using plus(BigMoneyProvider)
.
All amounts must be in the same currency.
monies
 the monetary values to total, not empty, no null elements, not nullIllegalArgumentException
 if the array is emptyCurrencyMismatchException
 if the currencies differpublic static BigMoney total(Iterable<? extends BigMoneyProvider> monies)
BigMoney
as the total value of a collection.
The iterable must provide at least one monetary value.
Subsequent amounts are added as though using plus(BigMoneyProvider)
.
All amounts must be in the same currency.
monies
 the monetary values to total, not empty, no null elements, not nullIllegalArgumentException
 if the iterable is emptyCurrencyMismatchException
 if the currencies differpublic static BigMoney total(CurrencyUnit currency, BigMoneyProvider... monies)
Money
as the total value of
a possibly empty array.
The amounts are added as though using plus(BigMoneyProvider)
starting
from zero in the specified currency.
All amounts must be in the same currency.
currency
 the currency to total in, not nullmonies
 the monetary values to total, no null elements, not nullCurrencyMismatchException
 if the currencies differpublic static BigMoney total(CurrencyUnit currency, Iterable<? extends BigMoneyProvider> monies)
Money
as the total value of
a possibly empty collection.
The amounts are added as though using plus(BigMoneyProvider)
starting
from zero in the specified currency.
All amounts must be in the same currency.
currency
 the currency to total in, not nullmonies
 the monetary values to total, no null elements, not nullCurrencyMismatchException
 if the currencies differpublic static BigMoney parse(String moneyStr)
BigMoney
from a string.
The string format is '$currencyCode $amount' where there may be
zero to many spaces between the two parts.
The currency code must be a valid three letter currency.
The amount must match the regular expression [+]?[09]*[.]?[09]*
.
The spaces and numbers must be ASCII characters.
This matches the output from toString()
.
For example, parse("USD 25")
creates the instance USD 25
while parse("USD 25.95")
creates the instance USD 25.95
.
moneyStr
 the money string to parse, not nullIllegalArgumentException
 if the string is malformedArithmeticException
 if the amount is too largepublic static BigMoney nonNull(BigMoney money, CurrencyUnit currency)
BigMoney
is not null
.
If the input money is not null
, then it is returned, providing
that the currency matches the specified currency.
If the input money is null
, then zero money in the currency
is returned with a scale of zero.
money
 the monetary value to check, may be nullcurrency
 the currency to use, not nullCurrencyMismatchException
 if the input money is nonnull and the currencies differpublic CurrencyUnit getCurrencyUnit()
public BigMoney withCurrencyUnit(CurrencyUnit currency)
The returned instance will have the specified currency and the amount from this instance. No currency conversion or alteration to the scale occurs.
This instance is immutable and unaffected by this method.
currency
 the currency to use, not nullpublic int getScale()
BigDecimal
amount.
The scale has the same meaning as in BigDecimal
.
Positive values represent the number of decimal places in use.
Negative numbers represent the opposite.
For example, a scale of 2 means that the money will have two decimal places
such as 'USD 43.25'. The scale of will not be negative.
withScale(int)
public boolean isCurrencyScale()
Each currency has a default scale, such as 2 for USD and 0 for JPY. This method checks if the current scale matches the default scale.
public BigMoney withScale(int scale)
The returned instance will have this currency and the new scaled amount. For example, scaling 'USD 43.2' to a scale of 2 will yield 'USD 43.20'. No rounding is performed on the amount, so it must have a scale less than or equal to the new scale. A negative scale may be passed in, but the result will have a minimum scale of zero.
This instance is immutable and unaffected by this method.
scale
 the scale to useArithmeticException
 if the rounding failspublic BigMoney withScale(int scale, RoundingMode roundingMode)
The returned instance will have this currency and the new scaled amount. For example, scaling 'USD 43.271' to a scale of 1 with HALF_EVEN rounding will yield 'USD 43.3'. A negative scale may be passed in, but the result will have a minimum scale of zero.
This instance is immutable and unaffected by this method.
scale
 the scale to useroundingMode
 the rounding mode to use, not nullArithmeticException
 if the rounding failspublic BigMoney withCurrencyScale()
The returned instance will have this currency and the new scaled amount. For example, scaling 'USD 43.271' will yield 'USD 43.27' as USD has a scale of 2. No rounding is performed on the amount, so it must have a scale less than or equal to the new scale.
This instance is immutable and unaffected by this method.
ArithmeticException
 if the rounding failspublic BigMoney withCurrencyScale(RoundingMode roundingMode)
The returned instance will have this currency and the new scaled amount. For example, scaling 'USD 43.271' will yield 'USD 43.27' as USD has a scale of 2.
This instance is immutable and unaffected by this method.
roundingMode
 the rounding mode to use, not nullArithmeticException
 if the rounding failspublic BigDecimal getAmount()
This returns the value of the money as a BigDecimal
.
The scale will be the scale of this money.
public BigDecimal getAmountMajor()
BigDecimal
with scale 0.
This returns the monetary amount in terms of the major units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 2, and 'BHD 1.345' will return 1.
This is returned as a BigDecimal
rather than a BigInteger
.
This is to allow further calculations to be performed on the result.
Should you need a BigInteger
, simply call BigDecimal.toBigInteger()
.
public long getAmountMajorLong()
long
.
This returns the monetary amount in terms of the major units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 2, and 'BHD 1.345' will return 1.
ArithmeticException
 if the amount is too large for a long
public int getAmountMajorInt()
int
.
This returns the monetary amount in terms of the major units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 2, and 'BHD 1.345' will return 1.
ArithmeticException
 if the amount is too large for an int
public BigDecimal getAmountMinor()
BigDecimal
with scale 0.
This returns the monetary amount in terms of the minor units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 235, and 'BHD 1.345' will return 1345.
This is returned as a BigDecimal
rather than a BigInteger
.
This is to allow further calculations to be performed on the result.
Should you need a BigInteger
, simply call BigDecimal.toBigInteger()
.
public long getAmountMinorLong()
long
.
This returns the monetary amount in terms of the minor units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 235, and 'BHD 1.345' will return 1345.
ArithmeticException
 if the amount is too large for a long
public int getAmountMinorInt()
int
.
This returns the monetary amount in terms of the minor units of the currency, truncating the amount if necessary. For example, 'EUR 2.35' will return 235, and 'BHD 1.345' will return 1345.
ArithmeticException
 if the amount is too large for an int
public int getMinorPart()
This return the minor unit part of the monetary amount. This is defined as the amount in minor units excluding major units.
For example, EUR has a scale of 2, so the minor part is always between 0 and 99 for positive amounts, and 0 and 99 for negative amounts. Thus 'EUR 2.35' will return 35, and 'EUR 1.34' will return 34.
public boolean isZero()
public boolean isPositive()
public boolean isPositiveOrZero()
public boolean isNegative()
public boolean isNegativeOrZero()
public BigMoney withAmount(BigDecimal amount)
The returned instance will have this currency and the new amount. The scale of the returned instance will be that of the specified BigDecimal.
This instance is immutable and unaffected by this method.
amount
 the monetary amount to set in the returned instance, not nullpublic BigMoney withAmount(double amount)
double
.
The returned instance will have this currency and the new amount.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.425d' will be converted to '1.425'.
The scale of the money will be that of the BigDecimal produced.
This instance is immutable and unaffected by this method.
amount
 the monetary amount to set in the returned instancepublic BigMoney plus(Iterable<? extends BigMoneyProvider> moniesToAdd)
This adds the specified amounts to this monetary amount, returning a new object.
The amounts are added as though using plus(BigMoneyProvider)
.
The amounts must be in the same currency.
This instance is immutable and unaffected by this method.
moniesToAdd
 the monetary values to add, no null elements, not nullCurrencyMismatchException
 if the currencies differpublic BigMoney plus(BigMoneyProvider moneyToAdd)
This adds the specified amount to this monetary amount, returning a new object. The amount added must be in the same currency.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example, 'USD 25.95' plus 'USD 3.021' gives 'USD 28.971'.
This instance is immutable and unaffected by this method.
moneyToAdd
 the monetary value to add, not nullCurrencyMismatchException
 if the currencies differpublic BigMoney plus(BigDecimal amountToAdd)
This adds the specified amount to this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example, 'USD 25.95' plus '3.021' gives 'USD 28.971'.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullpublic BigMoney plus(double amountToAdd)
This adds the specified amount to this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example, 'USD 25.95' plus '3.021d' gives 'USD 28.971'.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullpublic BigMoney plusMajor(long amountToAdd)
This adds the specified amount in major units to this monetary amount, returning a new object. The minor units will be untouched in the result.
No precision is lost in the result. The scale of the result will be the maximum of the current scale and 0. For example, 'USD 23.45' plus '138' gives 'USD 161.45'.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullpublic BigMoney plusMinor(long amountToAdd)
This adds the specified amount in minor units to this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the current scale and the default currency scale. For example, 'USD 23.45' plus '138' gives 'USD 24.83'.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullpublic BigMoney plusRetainScale(BigMoneyProvider moneyToAdd, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' plus 'USD 3.021' gives 'USD 28.97' with most rounding modes.
This instance is immutable and unaffected by this method.
moneyToAdd
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney plusRetainScale(BigDecimal amountToAdd, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' plus '3.021' gives 'USD 28.97' with most rounding modes.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney plusRetainScale(double amountToAdd, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' plus '3.021d' gives 'USD 28.97' with most rounding modes.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
amountToAdd
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney minus(Iterable<? extends BigMoneyProvider> moniesToSubtract)
This subtracts the specified amounts from this monetary amount, returning a new object.
The amounts are subtracted one by one as though using minus(BigMoneyProvider)
.
The amounts must be in the same currency.
This instance is immutable and unaffected by this method.
moniesToSubtract
 the monetary values to subtract, no null elements, not nullCurrencyMismatchException
 if the currencies differpublic BigMoney minus(BigMoneyProvider moneyToSubtract)
This subtracts the specified amount from this monetary amount, returning a new object. The amount subtracted must be in the same currency.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example,'USD 25.95' minus 'USD 3.021' gives 'USD 22.929'.
This instance is immutable and unaffected by this method.
moneyToSubtract
 the monetary value to subtract, not nullCurrencyMismatchException
 if the currencies differpublic BigMoney minus(BigDecimal amountToSubtract)
This subtracts the specified amount from this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example,'USD 25.95' minus '3.021' gives 'USD 22.929'.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to subtract, not nullpublic BigMoney minus(double amountToSubtract)
This subtracts the specified amount from this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the two scales. For example,'USD 25.95' minus '3.021d' gives 'USD 22.929'.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to subtract, not nullpublic BigMoney minusMajor(long amountToSubtract)
This subtracts the specified amount in major units from this monetary amount, returning a new object. The minor units will be untouched in the result.
No precision is lost in the result. The scale of the result will be the maximum of the current scale and 0. For example, 'USD 23.45' minus '138' gives 'USD 114.55'.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to subtract, not nullpublic BigMoney minusMinor(long amountToSubtract)
This subtracts the specified amount in minor units from this monetary amount, returning a new object.
No precision is lost in the result. The scale of the result will be the maximum of the current scale and the default currency scale. For example, USD 23.45 minus '138' gives 'USD 22.07'.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to subtract, not nullpublic BigMoney minusRetainScale(BigMoneyProvider moneyToSubtract, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' minus 'USD 3.029' gives 'USD 22.92 with most rounding modes.
This instance is immutable and unaffected by this method.
moneyToSubtract
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney minusRetainScale(BigDecimal amountToSubtract, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' minus '3.029' gives 'USD 22.92' with most rounding modes.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney minusRetainScale(double amountToSubtract, RoundingMode roundingMode)
The scale of the result will be the same as the scale of this instance. For example,'USD 25.95' minus '3.029d' gives 'USD 22.92' with most rounding modes.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
amountToSubtract
 the monetary value to add, not nullroundingMode
 the rounding mode to use to adjust the scale, not nullpublic BigMoney multipliedBy(BigDecimal valueToMultiplyBy)
No precision is lost in the result. The result has a scale equal to the sum of the two scales. For example, 'USD 1.13' multiplied by '2.5' gives 'USD 2.825'.
This instance is immutable and unaffected by this method.
valueToMultiplyBy
 the scalar value to multiply by, not nullpublic BigMoney multipliedBy(double valueToMultiplyBy)
No precision is lost in the result. The result has a scale equal to the sum of the two scales. For example, 'USD 1.13' multiplied by '2.5' gives 'USD 2.825'.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
valueToMultiplyBy
 the scalar value to multiply by, not nullpublic BigMoney multipliedBy(long valueToMultiplyBy)
No precision is lost in the result. The result has a scale equal to the scale of this money. For example, 'USD 1.13' multiplied by '2' gives 'USD 2.26'.
This instance is immutable and unaffected by this method.
valueToMultiplyBy
 the scalar value to multiply by, not nullpublic BigMoney multiplyRetainScale(BigDecimal valueToMultiplyBy, RoundingMode roundingMode)
This multiplies this money by the specified value, retaining the scale of this money. This will frequently lose precision, hence the need for a rounding mode. For example, 'USD 1.13' multiplied by '2.5' and rounding down gives 'USD 2.82'.
This instance is immutable and unaffected by this method.
valueToMultiplyBy
 the scalar value to multiply by, not nullroundingMode
 the rounding mode to use to bring the decimal places back in line, not nullArithmeticException
 if the rounding failspublic BigMoney multiplyRetainScale(double valueToMultiplyBy, RoundingMode roundingMode)
This multiplies this money by the specified value, retaining the scale of this money. This will frequently lose precision, hence the need for a rounding mode. For example, 'USD 1.13' multiplied by '2.5' and rounding down gives 'USD 2.82'.
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
valueToMultiplyBy
 the scalar value to multiply by, not nullroundingMode
 the rounding mode to use to bring the decimal places back in line, not nullArithmeticException
 if the rounding failspublic BigMoney dividedBy(BigDecimal valueToDivideBy, RoundingMode roundingMode)
The result has the same scale as this instance. For example, 'USD 1.13' divided by '2.5' and rounding down gives 'USD 0.45' (amount rounded down from 0.452).
This instance is immutable and unaffected by this method.
valueToDivideBy
 the scalar value to divide by, not nullroundingMode
 the rounding mode to use, not nullArithmeticException
 if dividing by zeroArithmeticException
 if the rounding failspublic BigMoney dividedBy(double valueToDivideBy, RoundingMode roundingMode)
The result has the same scale as this instance. For example, 'USD 1.13' divided by '2.5' and rounding down gives 'USD 0.45' (amount rounded down from 0.452).
The amount is converted via BigDecimal.valueOf(double)
which yields
the most expected answer for most programming scenarios.
Any double
literal in code will be converted to
exactly the same BigDecimal with the same scale.
For example, the literal '1.45d' will be converted to '1.45'.
This instance is immutable and unaffected by this method.
valueToDivideBy
 the scalar value to divide by, not nullroundingMode
 the rounding mode to use, not nullArithmeticException
 if dividing by zeroArithmeticException
 if the rounding failspublic BigMoney dividedBy(long valueToDivideBy, RoundingMode roundingMode)
The result has the same scale as this instance. For example, 'USD 1.13' divided by '2' and rounding down gives 'USD 0.56' (amount rounded down from 0.565).
This instance is immutable and unaffected by this method.
valueToDivideBy
 the scalar value to divide by, not nullroundingMode
 the rounding mode to use, not nullArithmeticException
 if dividing by zeropublic BigMoney negated()
This instance is immutable and unaffected by this method.
public BigMoney abs()
This instance is immutable and unaffected by this method.
public BigMoney rounded(int scale, RoundingMode roundingMode)
Scale is described in BigDecimal
and represents the point below which
the monetary value is zero. Negative scales round increasingly large numbers.
Unlike withScale(int)
, this scale of the result is unchanged.
scale
 the new scaleroundingMode
 the rounding mode to use, not nullArithmeticException
 if the rounding failspublic BigMoney convertedTo(CurrencyUnit currency, BigDecimal conversionMultipler)
The scale of the result will be the sum of the scale of this money and
the scale of the multiplier. If desired, the scale of the result can be
adjusted to the scale of the new currency using withCurrencyScale()
.
This instance is immutable and unaffected by this method.
currency
 the new currency, not nullconversionMultipler
 the conversion factor between the currencies, not nullIllegalArgumentException
 if the currency is the same as this currency and the
conversion is not one; or if the conversion multiplier is negativepublic BigMoney convertRetainScale(CurrencyUnit currency, BigDecimal conversionMultipler, RoundingMode roundingMode)
The result will have the same scale as this instance even though it will be in a different currency.
This instance is immutable and unaffected by this method.
currency
 the new currency, not nullconversionMultipler
 the conversion factor between the currencies, not nullroundingMode
 the rounding mode to use to bring the decimal places back in line, not nullIllegalArgumentException
 if the currency is the same as this currency and the
conversion is not one; or if the conversion multiplier is negativeArithmeticException
 if the rounding failspublic BigMoney toBigMoney()
BigMoneyProvider
interface, trivially
returning this
.toBigMoney
in interface BigMoneyProvider
public Money toMoney()
Money
without rounding.
If the scale of this money exceeds the currency scale an exception will be thrown.ArithmeticException
 if the rounding failspublic Money toMoney(RoundingMode roundingMode)
Money
.roundingMode
 the rounding mode to use, not nullArithmeticException
 if the rounding failspublic boolean isSameCurrency(BigMoneyProvider money)
money
 the money to check, not nullpublic int compareTo(BigMoneyProvider other)
compareTo
in interface Comparable<BigMoneyProvider>
other
 the other monetary value, not nullCurrencyMismatchException
 if the currencies differpublic boolean isEqual(BigMoneyProvider other)
This ignores the scale of the amount. Thus, 'USD 30.00' and 'USD 30' are equal.
The compared values must be in the same currency.
other
 the other monetary value, not nullCurrencyMismatchException
 if the currencies differequals(Object)
public boolean isGreaterThan(BigMoneyProvider other)
other
 the other monetary value, not nullCurrencyMismatchException
 if the currencies differpublic boolean isLessThan(BigMoneyProvider other)
other
 the other monetary value, not nullCurrencyMismatchException
 if the currencies differpublic boolean equals(Object other)
Like BigDecimal, this method compares the scale of the amount. Thus, 'USD 30.00' and 'USD 30' are not equal.
The compared values must be in the same currency.
equals
in class Object
other
 the other object, null returns falseisEqual(org.joda.money.BigMoneyProvider)
public int hashCode()
public String toString()
The format is the 3 letter ISO currency code, followed by a space,
followed by the amount as per BigDecimal.toPlainString()
.
Copyright © 2009–2016 Joda.org. All rights reserved.