Top Description Fields Constructors Methods
org.joda.money

public final Class BigMoney

extends Object
implements BigMoneyProvider, Comparable<BigMoneyProvider>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, org.joda.money.BigMoneyProvider
Imports
java.io.InvalidObjectException, .ObjectInputStream, .Serializable, java.math.BigDecimal, .BigInteger, .RoundingMode, java.util.Arrays, .Iterator, java.util.regex.Pattern, org.joda.convert.FromString, .ToString

An amount of money with unrestricted decimal place precision.

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 thread-safe.

Field Summary

Modifier and TypeField and Description
private final BigDecimal
amount

The amount, not null.

private final CurrencyUnit
currency

The currency, not null.

private static final Pattern
PARSE_REGEX

The regex for parsing.

private static final long
serialVersionUID

The serialisation version.

Constructor Summary

AccessConstructor and Description
private
BigMoney()

Private no-args constructor, for use as JPA Embeddable (for example).

pack-priv
BigMoney(CurrencyUnit
the currency to use, not null
currency
,
BigDecimal
the amount of money, not null
amount
)

Constructor, creating a new monetary instance.

Method Summary

Modifier and TypeMethod and Description
public BigMoney

Returns:

the new instance with the amount converted to be positive, never null
abs
()

Returns a copy of this monetary value with a positive amount.

private BigMoney
checkCurrencyEqual(BigMoneyProvider
the money to check, not null
moneyProvider
)

Validates that the currency of this money and the specified money match.

public int

Returns:

-1 if this is less than , 0 if equal, 1 if greater than
compareTo
(BigMoneyProvider
the other monetary value, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this monetary value to another.

public BigMoney

Returns:

the new multiplied instance, never null
convertedTo
(CurrencyUnit
the new currency, not null
currency
,
BigDecimal
the conversion factor between the currencies, not null
conversionMultipler
)

Returns a copy of this monetary value converted into another currency using the specified conversion rate.

public BigMoney

Returns:

the new multiplied instance, never null
convertRetainScale
(CurrencyUnit
the new currency, not null
currency
,
BigDecimal
the conversion factor between the currencies, not null
conversionMultipler
,
RoundingMode
the rounding mode to use to bring the decimal places back in line, not null
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.

public BigMoney

Returns:

the new divided instance, never null
dividedBy
(BigDecimal
the scalar value to divide by, not null
valueToDivideBy
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Returns a copy of this monetary value divided by the specified value using the specified rounding mode to adjust the scale.

public BigMoney

Returns:

the new divided instance, never null
dividedBy
(double
the scalar value to divide by, not null
valueToDivideBy
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Returns a copy of this monetary value divided by the specified value using the specified rounding mode to adjust the scale.

public BigMoney

Returns:

the new divided instance, never null
dividedBy
(long
the scalar value to divide by, not null
valueToDivideBy
,
RoundingMode
the rounding mode to use, not null
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.

public boolean

Returns:

true if this instance equals the other instance
equals
(Object
the other object, null returns false
other
)

Overrides java.lang.Object.equals.

Checks if this monetary value equals another.

public BigDecimal

Returns:

the amount, never null
getAmount
()

Gets the amount.

public BigDecimal

Returns:

the major units part of the amount, never null
getAmountMajor
()

Gets the amount in major units as a BigDecimal with scale 0.

public int

Returns:

the major units part of the amount
getAmountMajorInt
()

Gets the amount in major units as an int.

public long

Returns:

the major units part of the amount
getAmountMajorLong
()

Gets the amount in major units as a long.

public BigDecimal

Returns:

the minor units part of the amount, never null
getAmountMinor
()

Gets the amount in minor units as a BigDecimal with scale 0.

public int

Returns:

the minor units part of the amount
getAmountMinorInt
()

Gets the amount in minor units as an int.

public long

Returns:

the minor units part of the amount
getAmountMinorLong
()

Gets the amount in minor units as a long.

public CurrencyUnit

Returns:

the currency, never null
getCurrencyUnit
()

Gets the currency.

public int

Returns:

the minor part of the amount, negative if the amount is negative
getMinorPart
()

Gets the minor part of the amount.

public int

Returns:

the scale in use
getScale
()

Gets the scale of the BigDecimal amount.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this monetary value.

public boolean

Returns:

true if the scale equals the current default scale
isCurrencyScale
()

Checks if this money has the scale of the currency.

public boolean

Returns:

true if this is equal to the specified monetary value
isEqual
(BigMoneyProvider
the other monetary value, not null
other
)

Checks if this monetary value is equal to another.

public boolean

Returns:

true if this is greater than the specified monetary value
isGreaterThan
(BigMoneyProvider
the other monetary value, not null
other
)

Checks if this monetary value is greater than another.

public boolean

Returns:

true if this is greater than or equal to the specified monetary value
isGreaterThanOrEqual
(BigMoneyProvider
the other monetary value, not null
other
)

Checks if this monetary value is greater than or equal to another.

public boolean

Returns:

true if this is less than the specified monetary value
isLessThan
(BigMoneyProvider
the other monetary value, not null
other
)

Checks if this monetary value is less than another.

public boolean

Returns:

true if this is less than or equal to the specified monetary value
isLessThanOrEqual
(BigMoneyProvider
the other monetary value, not null
other
)

Checks if this monetary value is less or equal to than another.

public boolean

Returns:

true if the amount is less than zero
isNegative
()

Checks if the amount is less than zero.

public boolean

Returns:

true if the amount is zero or less
isNegativeOrZero
()

Checks if the amount is zero or less.

public boolean

Returns:

true if the amount is greater than zero
isPositive
()

Checks if the amount is greater than zero.

public boolean

Returns:

true if the amount is zero or greater
isPositiveOrZero
()

Checks if the amount is zero or greater.

public boolean

Returns:

true if they have the same currency
isSameCurrency
(BigMoneyProvider
the money to check, not null
money
)

Checks if this instance and the specified instance have the same currency.

public boolean

Returns:

true if the amount is zero
isZero
()

Checks if the amount is zero.

public BigMoney

Returns:

the new instance with the input amounts subtracted, never null
minus
(Iterable<? extends BigMoneyProvider>
the monetary values to subtract, no null elements, not null
moniesToSubtract
)

Returns a copy of this monetary value with a collection of monetary amounts subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minus
(BigMoneyProvider
the monetary value to subtract, not null
moneyToSubtract
)

Returns a copy of this monetary value with the amount subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minus
(BigDecimal
the monetary value to subtract, not null
amountToSubtract
)

Returns a copy of this monetary value with the amount subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minus
(double
the monetary value to subtract, not null
amountToSubtract
)

Returns a copy of this monetary value with the amount subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minusMajor
(long
the monetary value to subtract, not null
amountToSubtract
)

Returns a copy of this monetary value with the amount in major units subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minusMinor
(long
the monetary value to subtract, not null
amountToSubtract
)

Returns a copy of this monetary value with the amount in minor units subtracted.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minusRetainScale
(BigMoneyProvider
the monetary value to add, not null
moneyToSubtract
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount in the same currency subtracted retaining the scale by rounding the result.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minusRetainScale
(BigDecimal
the monetary value to add, not null
amountToSubtract
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount subtracted retaining the scale by rounding the result.

public BigMoney

Returns:

the new instance with the input amount subtracted, never null
minusRetainScale
(double
the monetary value to add, not null
amountToSubtract
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount subtracted retaining the scale by rounding the result.

public BigMoney

Returns:

the new multiplied instance, never null
multipliedBy
(BigDecimal
the scalar value to multiply by, not null
valueToMultiplyBy
)

Returns a copy of this monetary value multiplied by the specified value.

public BigMoney

Returns:

the new multiplied instance, never null
multipliedBy
(double
the scalar value to multiply by, not null
valueToMultiplyBy
)

Returns a copy of this monetary value multiplied by the specified value.

public BigMoney

Returns:

the new multiplied instance, never null
multipliedBy
(long
the scalar value to multiply by, not null
valueToMultiplyBy
)

Returns a copy of this monetary value multiplied by the specified value.

public BigMoney

Returns:

the new multiplied instance, never null
multiplyRetainScale
(BigDecimal
the scalar value to multiply by, not null
valueToMultiplyBy
,
RoundingMode
the rounding mode to use to bring the decimal places back in line, not null
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.

public BigMoney

Returns:

the new multiplied instance, never null
multiplyRetainScale
(double
the scalar value to multiply by, not null
valueToMultiplyBy
,
RoundingMode
the rounding mode to use to bring the decimal places back in line, not null
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.

public BigMoney

Returns:

the new instance with the amount negated, never null
negated
()

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

public static BigMoney

Returns:

the new instance, never null
of
(CurrencyUnit
the currency, not null
currency
,
BigDecimal
the amount of money, not null
amount
)

Obtains an instance of BigMoney from a BigDecimal.

public static BigMoney

Returns:

the new instance, never null
of
(CurrencyUnit
the currency, not null
currency
,
double
the amount of money, not null
amount
)

Obtains an instance of BigMoney from a double using a well-defined conversion.

public static BigMoney

Returns:

the new instance, never null
of
(BigMoneyProvider
the money to convert, not null
moneyProvider
)

Obtains an instance of BigMoney from a provider.

public static BigMoney

Returns:

the new instance, never null
ofMajor
(CurrencyUnit
the currency, not null
currency
,
long
the amount of money in the major division of the currency
amountMajor
)

Obtains an instance of BigMoney from an amount in major units.

public static BigMoney

Returns:

the new instance, never null
ofMinor
(CurrencyUnit
the currency, not null
currency
,
long
the amount of money in the minor division of the currency
amountMinor
)

Obtains an instance of BigMoney from an amount in minor units.

public static BigMoney

Returns:

the new instance, never null
ofScale
(CurrencyUnit
the currency, not null
currency
,
BigDecimal
the amount of money, not null
amount
,
int
the scale to use, zero or positive
scale
)

Obtains an instance of BigMoney from a BigDecimal at a specific scale.

public static BigMoney

Returns:

the new instance, never null
ofScale
(CurrencyUnit
the currency, not null
currency
,
BigDecimal
the amount of money, not null
amount
,
int
the scale to use, zero or positive
scale
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Obtains an instance of BigMoney from a double using a well-defined conversion, rounding as necessary.

public static BigMoney

Returns:

the new instance, never null
ofScale
(CurrencyUnit
the currency, not null
currency
,
long
the unscaled amount of money
unscaledAmount
,
int
the scale to use
scale
)

Obtains an instance of BigMoney from a scaled amount.

public static BigMoney

Returns:

the parsed instance, never null
parse
(String
the money string to parse, not null
moneyStr
)

Parses an instance of BigMoney from a string.

public BigMoney

Returns:

the new instance with the input amounts added, never null
plus
(Iterable<? extends BigMoneyProvider>
the monetary values to add, no null elements, not null
moniesToAdd
)

Returns a copy of this monetary value with a collection of monetary amounts added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plus
(BigMoneyProvider
the monetary value to add, not null
moneyToAdd
)

Returns a copy of this monetary value with the amount added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plus
(BigDecimal
the monetary value to add, not null
amountToAdd
)

Returns a copy of this monetary value with the amount added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plus
(double
the monetary value to add, not null
amountToAdd
)

Returns a copy of this monetary value with the amount added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plusMajor
(long
the monetary value to add, not null
amountToAdd
)

Returns a copy of this monetary value with the amount in major units added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plusMinor
(long
the monetary value to add, not null
amountToAdd
)

Returns a copy of this monetary value with the amount in minor units added.

public BigMoney

Returns:

the new instance with the input amount added, never null
plusRetainScale
(BigMoneyProvider
the monetary value to add, not null
moneyToAdd
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount in the same currency added retaining the scale by rounding the result.

public BigMoney

Returns:

the new instance with the input amount added, never null
plusRetainScale
(BigDecimal
the monetary value to add, not null
amountToAdd
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount added retaining the scale by rounding the result.

public BigMoney

Returns:

the new instance with the input amount added, never null
plusRetainScale
(double
the monetary value to add, not null
amountToAdd
,
RoundingMode
the rounding mode to use to adjust the scale, not null
roundingMode
)

Returns a copy of this monetary value with the amount added retaining the scale by rounding the result.

private void
readObject(ObjectInputStream
the input stream, not null
ois
)

Block malicious data streams.

public BigMoney

Returns:

the new instance with the amount converted to be positive, never null
rounded
(int
the new scale
scale
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Returns a copy of this monetary value rounded to the specified scale without changing the current scale.

public BigMoney

Returns:

the money instance, never null
toBigMoney
()

Implements org.joda.money.BigMoneyProvider.toBigMoney.

Implements the BigMoneyProvider interface, trivially returning this.

public Money

Returns:

the money instance, never null
toMoney
()

Converts this money to an instance of Money without rounding.

public Money

Returns:

the money instance, never null
toMoney
(RoundingMode
the rounding mode to use, not null
roundingMode
)

Converts this money to an instance of Money.

public String

Returns:

the string representation of this monetary value, never null
toString
()

Overrides java.lang.Object.toString.

Gets this monetary value as a string.

public static BigMoney

Returns:

the total, never null
total
(BigMoneyProvider...
the monetary values to total, not empty, no null elements, not null
monies
)

Obtains an instance of BigMoney as the total value of an array.

public static BigMoney

Returns:

the total, never null
total
(Iterable<? extends BigMoneyProvider>
the monetary values to total, not empty, no null elements, not null
monies
)

Obtains an instance of BigMoney as the total value of a collection.

public static BigMoney

Returns:

the total, never null
total
(CurrencyUnit
the currency to total in, not null
currency
,
BigMoneyProvider...
the monetary values to total, no null elements, not null
monies
)

Obtains an instance of Money as the total value of a possibly empty array.

public static BigMoney

Returns:

the total, never null
total
(CurrencyUnit
the currency to total in, not null
currency
,
Iterable<? extends BigMoneyProvider>
the monetary values to total, no null elements, not null
monies
)

Obtains an instance of Money as the total value of a possibly empty collection.

private BigMoney

Returns:

the new instance, never null
with
(BigDecimal
the new amount to use, not null
newAmount
)

Returns a new BigMoney, returning this if possible.

public BigMoney

Returns:

the new instance with the input amount set, never null
withAmount
(BigDecimal
the monetary amount to set in the returned instance, not null
amount
)

Returns a copy of this monetary value with the specified amount.

public BigMoney

Returns:

the new instance with the input amount set, never null
withAmount
(double
the monetary amount to set in the returned instance
amount
)

Returns a copy of this monetary value with the specified amount using a well-defined conversion from a double.

public BigMoney

Returns:

the new instance with the input amount set, never null
withCurrencyScale
()

Returns a copy of this monetary value with the scale of the currency, truncating the amount if necessary.

public BigMoney

Returns:

the new instance with the input amount set, never null
withCurrencyScale
(RoundingMode
the rounding mode to use, not null
roundingMode
)

Returns a copy of this monetary value with the scale of the currency, using the specified rounding mode if necessary.

public BigMoney

Returns:

the new instance with the input currency set, never null
withCurrencyUnit
(CurrencyUnit
the currency to use, not null
currency
)

Returns a copy of this monetary value with the specified currency.

public BigMoney

Returns:

the new instance with the input amount set, never null
withScale
(int
the scale to use
scale
)

Returns a copy of this monetary value with the specified scale, truncating the amount if necessary.

public BigMoney

Returns:

the new instance with the input amount set, never null
withScale
(int
the scale to use
scale
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Returns a copy of this monetary value with the specified scale, using the specified rounding mode if necessary.

private Object

Returns:

the replacing object, never null
writeReplace
()

Uses a serialization delegate.

public static BigMoney

Returns:

the instance representing zero, never null
zero
(CurrencyUnit
the currency, not null
currency
)

Obtains an instance of BigMoney representing zero.

public static BigMoney

Returns:

the instance representing zero, never null
zero
(CurrencyUnit
the currency, not null
currency
,
int
the scale to use, zero or positive
scale
)

Obtains an instance of BigMoney representing zero at a specific scale.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait