Top Description Fields Constructors Methods
org.joda.money

public final Class Money

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, .RoundingMode, java.util.Arrays, org.joda.convert.FromString, .ToString

An amount of money with the standard decimal places defined by the currency.

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 Money class is fixed to this number of decimal places.

For example, US dollars has a standard number of decimal places of 2. The major units are dollars. The minor units are cents, 100 to the dollar. This class does not allow calculations on fractions of a cent.

This class is immutable and thread-safe.

Field Summary

Modifier and TypeField and Description
private final BigMoney
money

The money, not null.

private static final long
serialVersionUID

The serialisation version.

Constructor Summary

AccessConstructor and Description
private
Money()

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

pack-priv
Money(BigMoney
the underlying money, not null
money
)

Constructor, creating a new monetary instance.

Method Summary

Modifier and TypeMethod and Description
public Money

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.

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 Money

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
,
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 Money

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.

public Money

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.

public Money

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.

public boolean

Returns:

true if this instance equals the other instance
equals
(Object
the other object to compare to, not null
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, typically 2 but could be 0, 1 and 3
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 is this is greater than 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 is 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 is 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 is 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 is 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 than or equal to 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
other
)

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 Money

Returns:

the new instance with the input amounts subtracted, never null
minus
(Iterable<Money>
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 Money

Returns:

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

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

public Money

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 Money

Returns:

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

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

public Money

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 Money

Returns:

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

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

public Money

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 Money

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 Money

Returns:

the new multiplied instance, never null
multipliedBy
(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.

public Money

Returns:

the new multiplied instance, never null
multipliedBy
(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.

public Money

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 Money

Returns:

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

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

public static Money

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 Money from a BigDecimal.

public static Money

Returns:

the new instance, never null
of
(CurrencyUnit
the currency, not null
currency
,
BigDecimal
the amount of money, not null
amount
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Obtains an instance of Money from a BigDecimal, rounding as necessary.

public static Money

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 Money from a double using a well-defined conversion.

public static Money

Returns:

the new instance, never null
of
(CurrencyUnit
the currency, not null
currency
,
double
the amount of money, not null
amount
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

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

public static Money

Returns:

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

Obtains an instance of Money from a provider.

public static Money

Returns:

the new instance, never null
of
(BigMoneyProvider
the money to convert, not null
moneyProvider
,
RoundingMode
the rounding mode to use, not null
roundingMode
)

Obtains an instance of Money from a provider, rounding as necessary.

public static Money

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 Money from an amount in major units.

public static Money

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 Money from an amount in minor units.

public static Money

Returns:

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

Parses an instance of Money from a string.

public Money

Returns:

the new instance with the input amounts added, never null
plus
(Iterable<Money>
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 Money

Returns:

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

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

public Money

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 Money

Returns:

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

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

public Money

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 Money

Returns:

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

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

public Money

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 Money

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.

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

Block malicious data streams.

public Money

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, returning a BigMoney instance with the same currency, amount and scale.

public String

Returns:

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

Overrides java.lang.Object.toString.

Gets the monetary value as a string.

public static Money

Returns:

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

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

public static Money

Returns:

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

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

public static Money

Returns:

the total, never null
total
(CurrencyUnit
the currency to total in, not null
currency
,
Money...
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 Money

Returns:

the total, never null
total
(CurrencyUnit
the currency to total in, not null
currency
,
Iterable<Money>
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 Money

Returns:

the new instance, never null
with
(BigMoney
the new money to use, not null
newInstance
)

Returns a new Money, returning this if possible.

public Money

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 Money

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
,
RoundingMode
the rounding mode to adjust the scale, not null
roundingMode
)

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

public Money

Returns:

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

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

public Money

Returns:

the new instance with the input amount set, never null
withAmount
(double
the monetary amount to set in the returned instance, not null
amount
,
RoundingMode
the rounding mode to adjust the scale, not null
roundingMode
)

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

public Money

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 Money

Returns:

the new instance with the input currency set, never null
withCurrencyUnit
(CurrencyUnit
the currency to use, not null
currency
,
RoundingMode
the rounding mode to use to bring the decimal places back in line, not null
roundingMode
)

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

private Object

Returns:

the replacing object, never null
writeReplace
()

Uses a serialization delegate.

public static Money

Returns:

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

Obtains an instance of Money representing zero.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait