Represents a quantity of Money.
Represents a quantity of Money.
Money is similar to other quantities in that it represents an amount of something - purchasing power - and it is measured in units - currencies.
The main difference is that the conversion rate between currencies can not be certain at compile. (In fact it may not always be so easy to know them at runtime as well.)
To address this diversion from the way most other quantities work, Money overrides several of the standard methods and operators to ensure one of two rules is followed:
- this and that are in the same currency, or
- there is in an implicit MoneyContext in scope (which may or may not have the applicable exchange rate)
Methods and operations applied to moneys of different currencies may throw a NoSuchExchangeRateException if the implicit MoneyContext does not contain the Rate(s) necessary to perform the conversion.
The defaultMoneyContext includes USD as the default currency, a list of ~20 other currencies and NO exchange rates
- Value Params
- amount
the amount of money
- currency
the currency in which the money is denominated
- Authors
garyKeorkunian
- Since
0.1
- Companion
- object
Value members
Concrete methods
Integer divides this money by that BigDecimal and returns the remainder
Integer divides this money by that BigDecimal and returns the remainder
- Value Params
- that
BigDecimal
- Returns
Money
Multiplies this money by that squants.market.CurrencyExchangeRate and returns the equal value in the other currency.
Multiplies this money by that squants.market.CurrencyExchangeRate and returns the equal value in the other currency.
Delegates to CurrencyExchangeRate * Money
- Value Params
- that
BigDecimal
Integer divides this money by that BigDecimal and returns the quotient and the remainder
Integer divides this money by that BigDecimal and returns the quotient and the remainder
- Value Params
- that
BigDecimal
- Returns
(Money, Money)
Override for Quantity.compare to only work on Moneys of like Currency
Override for Quantity.compare to only work on Moneys of like Currency
- Value Params
- that
Money
- Returns
Int
- Definition Classes
- Quantity -> Ordered
Divides this money by that BigDecimal and returns a new Money
Divides this money by that BigDecimal and returns a new Money
- Value Params
- that
BigDecimal
- Returns
Money
Overrides Quantity.divide to ensure BigDecimal math is performed
Overrides Quantity.divide to ensure BigDecimal math is performed
- Value Params
- that
Double
- Returns
Quantity
- Definition Classes
Override for Quantity.divide to only work on Moneys of like Currency Cross currency subtractions should use moneyMinus
Override for Quantity.divide to only work on Moneys of like Currency Cross currency subtractions should use moneyMinus
- Value Params
- that
Money
- Returns
Double
- Definition Classes
Override for Quantity.equal to only match Moneys of like Currency
Override for Quantity.equal to only match Moneys of like Currency
- Value Params
- that
Money must be of matching value and unit
- Definition Classes
- Quantity -> Any
Override for Quantity.hashCode because Money doesn't contain a primary unit
Override for Quantity.hashCode because Money doesn't contain a primary unit
- Definition Classes
- Quantity -> Any
Reboxes this Money value in a Money in the given Currency
Reboxes this Money value in a Money in the given Currency
- Value Params
- context
MoneyContext required for cross currency operations
- unit
Currency
- Returns
Money
- Throws
- NoSuchExchangeRateException
when no exchange rate is available
Applies a function to the underlying amount of the Money, returning a Money in the same Currency
Applies a function to the underlying amount of the Money, returning a Money in the same Currency
- Value Params
- f
BigDecimal => BigDecimal function
- Returns
Money
Override for Quantity.max to only work on Moneys of like Currency
Override for Quantity.max to only work on Moneys of like Currency
- Value Params
- that
Money
- Returns
Int
- Definition Classes
Override for Quantity.max to only work on Moneys of like Currency
Override for Quantity.max to only work on Moneys of like Currency
- Value Params
- that
Quantity
- Returns
Int
- Definition Classes
Override Quantity.minus to only work on like currencies Cross currency subtractions should use moneyMinus
Override Quantity.minus to only work on like currencies Cross currency subtractions should use moneyMinus
- Value Params
- that
Money
- Returns
Money
- Throws
- scala.UnsupportedOperationException
when attempted on cross currencies
- Definition Classes
Supports compare operation on Moneys of dislike Currency
Supports compare operation on Moneys of dislike Currency
- Value Params
- moneyContext
MoneyContext
- that
Money
Divides this money by that money and returns the ratio between the converted amounts
Divides this money by that money and returns the ratio between the converted amounts
- Value Params
- context
MoneyContext
- that
Money
Supports equality comparisons on Moneys of dislike Currency
Supports equality comparisons on Moneys of dislike Currency
- Value Params
- moneyContext
MoneyContext
- that
Money
Supports max operation on Moneys of dislike Currency
Supports max operation on Moneys of dislike Currency
- Value Params
- moneyContext
MoneyContext
- that
Money
Supports min operation on Moneys of dislike Currency
Supports min operation on Moneys of dislike Currency
- Value Params
- moneyContext
MoneyContext
- that
Money
Subtracts that Money from this Money converted to this.currency via context
Subtracts that Money from this Money converted to this.currency via context
- Value Params
- context
MoneyContext required for cross currency operations
- that
Money
- Returns
Money
- Throws
- NoSuchExchangeRateException
when no exchange rate is available
Supports non-equality comparisons on Moneys of dislike Currency
Supports non-equality comparisons on Moneys of dislike Currency
- Value Params
- moneyContext
MoneyContext
- that
Money
Adds this Money to that Money converted to this.currency via context
Adds this Money to that Money converted to this.currency via context
- Value Params
- context
MoneyContext required for cross currency operations
- that
Money
- Returns
Money
- Throws
- NoSuchExchangeRateException
when no exchange rate is available
Overrides Quantity.plus to only work on like currencies. Cross currency additions should use moneyPlus
Overrides Quantity.plus to only work on like currencies. Cross currency additions should use moneyPlus
- Value Params
- that
Money
- Returns
Money
- Throws
- scala.UnsupportedOperationException
when attempted on cross currencies
- Definition Classes
Returns a Money rounded using scale and mode.
Returns a Money rounded using scale and mode.
- Value Params
- mode
RoundingMode - defaults to HALF_EVEN
- scale
Int - scale of the Money to be returned
- Returns
Quantity
- Definition Classes
Multiplies this money by that BigDecimal and returns a new Money
Multiplies this money by that BigDecimal and returns a new Money
- Value Params
- that
BigDecimal
- Returns
Money
Overrides Quantity.times to ensure BigDecimal math is performed
Overrides Quantity.times to ensure BigDecimal math is performed
- Value Params
- that
Double
- Returns
Quantity
- Definition Classes
Convert this Money to a Double representing the currency unit
Convert this Money to a Double representing the currency unit
- Value Params
- context
MoneyContext required for cross currency operations
- unit
Currency
- Returns
Double
- Throws
- NoSuchExchangeRateException
when no exchange rate is available
Returns a string formatted with the amount, rounded based on the Currency rules, and the currency symbol
Returns a string formatted with the amount, rounded based on the Currency rules, and the currency symbol
eg USD(12.4563) => "$123.46"
- Returns
String
Returns a string formatted with the original precision amount and the currency code
Returns a string formatted with the original precision amount and the currency code
eg USD(123.456) => "123.456 USD"
- Returns
String
- Definition Classes
- Quantity -> Any
Converts the amount to the given currency and returns a string formatted with the original precision and the currency code
Converts the amount to the given currency and returns a string formatted with the original precision and the currency code
- Value Params
- c
Currency
- context
MoneyContext required for conversion
Combines with that Money to create an squants.market.CurrencyExchangeRate
Combines with that Money to create an squants.market.CurrencyExchangeRate
Exchange Rates on the same currency are not supported
val rate: CurrencyExchangeRate = JPY(100) toThe USD(1)
- Value Params
- that
Money
- Throws
- scala.IllegalArgumentException
if the that.currency matches this.currency
Inherited methods
Returns the absolute value of this Quantity
Returns the absolute value of this Quantity
- Returns
Quantity
- Inherited from
- Quantity
Returns boolean result of approximate equality comparison
Returns boolean result of approximate equality comparison
- Value Params
- that
Quantity
- tolerance
Quantity
- Inherited from
- Quantity
Returns the smallest (closest to negative infinity) Quantity value that is greater than or equal to the argument and is equal to a mathematical integer.
Returns the smallest (closest to negative infinity) Quantity value that is greater than or equal to the argument and is equal to a mathematical integer.
- Returns
Quantity
- See also
java.lang.Math#ceil(double)
- Inherited from
- Quantity
Returns a Pair that includes the result of divideToInteger and remainder
Returns a Pair that includes the result of divideToInteger and remainder
- Value Params
- that
Quantity
- Returns
(Double, Quantity)
- Inherited from
- Quantity
Returns a Pair that includes the result of divideToInteger and remainder
Returns a Pair that includes the result of divideToInteger and remainder
- Value Params
- that
Double
- Returns
(Quantity, Quantity)
- Inherited from
- Quantity
Returns the largest (closest to positive infinity) Quantity value that is less than or equal to the argument and is equal to a mathematical integer
Returns the largest (closest to positive infinity) Quantity value that is less than or equal to the argument and is equal to a mathematical integer
- Returns
Quantity
- See also
java.lang.Math#floor(double)
- Inherited from
- Quantity
Returns an equivalent Quantity boxed with the supplied Unit
Returns an equivalent Quantity boxed with the supplied Unit
- Value Params
- uom
UnitOfMeasure[A]
- Returns
Quantity
- Inherited from
- Quantity
Applies a function to the underlying value of the Quantity, returning a new Quantity in the same unit
Applies a function to the underlying value of the Quantity, returning a new Quantity in the same unit
- Value Params
- f
Double => Double function
- Inherited from
- Quantity
Returns the negative value of this Quantity
Returns the negative value of this Quantity
- Returns
Quantity
- Inherited from
- Quantity
Returns true if this value is not within (contains) the range
Returns true if this value is not within (contains) the range
- Value Params
- range
QuantityRange
- Returns
Boolean
- Inherited from
- Quantity
Returns a QuantityRange representing the range for this value +- that
Returns a QuantityRange representing the range for this value +- that
- Value Params
- that
Quantity
- Returns
QuantityRange
- Inherited from
- Quantity
Returns the remainder of a division by a like quantity
Returns the remainder of a division by a like quantity
- Value Params
- that
Quantity
- Returns
Double
- Inherited from
- Quantity
Returns the remainder of a division by a number
Returns the remainder of a division by a number
- Value Params
- that
Quantity
- Returns
Quantity
- Inherited from
- Quantity
Returns the Quantity value that is closest in value to the argument and is equal to a mathematical integer.
Returns the Quantity value that is closest in value to the argument and is equal to a mathematical integer.
- Returns
Quantity
- See also
java.lang.Math#rint(double)
- Inherited from
- Quantity
Returns a Double representing the quantity in terms of the supplied unit
Returns a Double representing the quantity in terms of the supplied unit
val d = Feet(3)
(d to Inches) should be(36)
- Value Params
- uom
UnitOfMeasure[A]
- Returns
Double
- Inherited from
- Quantity
Returns a QuantityRange that goes from this to that
Returns a QuantityRange that goes from this to that
- Value Params
- that
Quantity
- Returns
QuantityRange
- Inherited from
- Quantity
Returns a string representing the quantity's value in the given unit
in the given format
Returns a string representing the quantity's value in the given unit
in the given format
- Value Params
- format
String containing the format for the value (ie "%.3f")
- uom
UnitOfMeasure[A] with UnitConverter
- Returns
String
- Inherited from
- Quantity
Returns a string representing the quantity's value in the given unit
Returns a string representing the quantity's value in the given unit
- Value Params
- uom
UnitOfMeasure[A] with UnitConverter
- Returns
String
- Inherited from
- Quantity
Returns a pair representing the numeric value and the uom's symbol
Returns a pair representing the numeric value and the uom's symbol
- Value Params
- uom
UnitOfMeasure[A]
- Inherited from
- Quantity
Returns a tuple representing the numeric value and the unit's symbol
Returns a tuple representing the numeric value and the unit's symbol
- Inherited from
- Quantity
Returns true if this value is within (contains) the range
Returns true if this value is within (contains) the range
- Value Params
- range
QuantityRange
- Returns
Boolean
- Inherited from
- Quantity