final class Money extends Quantity[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:
1) this and that are in the same currency, or 2) 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
- Source
- Money.scala
- Since
0.1
- Alphabetic
- By Inheritance
- Money
- Quantity
- Ordered
- Comparable
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def !=#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
%(that: BigDecimal): Money
Integer divides this money by that BigDecimal and returns the remainder
Integer divides this money by that BigDecimal and returns the remainder
- that
BigDecimal
- returns
Money
-
def
%(that: Money): Double
- Definition Classes
- Quantity
-
def
%(that: Double): Money
- Definition Classes
- Quantity
-
def
*(that: CurrencyExchangeRate): 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
- that
BigDecimal
-
def
*(that: BigDecimal): Money
Multiplies this money by that BigDecimal and returns a new Money
Multiplies this money by that BigDecimal and returns a new Money
- that
BigDecimal
- returns
Money
-
def
*(that: Double): Money
- Definition Classes
- Quantity
-
def
+(that: Money)(implicit context: MoneyContext = defaultMoneyContext): Money
moneyPlus *
-
def
+(that: Money): Money
- Definition Classes
- Quantity
-
def
+-(that: Money): QuantityRange[Money]
- Definition Classes
- Quantity
-
def
-(that: Money)(implicit context: MoneyContext = defaultMoneyContext): Money
moneyMinus *
-
def
-(that: Money): Money
- Definition Classes
- Quantity
-
def
->: (Money) ⇒ CurrencyExchangeRate
toThe
-
def
/[A <: Quantity[A]](that: Price[A]): A
Divide this money by a Price and return Quantity
Divide this money by a Price and return Quantity
- A
Quantity Type
- that
Price
- returns
A
-
def
/[A <: Quantity[A]](that: A): Price[A]
Divide this money by another (non-money) Quantity and return a Price
Divide this money by another (non-money) Quantity and return a Price
- A
Quantity Type
- that
Quantity
- returns
Price[A]
- def /(that: Money)(implicit context: MoneyContext = defaultMoneyContext): BigDecimal
-
def
/(that: BigDecimal): Money
Divides this money by that BigDecimal and returns a new Money
Divides this money by that BigDecimal and returns a new Money
- that
BigDecimal
- returns
Money
-
def
/(that: Money): Double
- Definition Classes
- Quantity
-
def
/(that: Double): Money
- Definition Classes
- Quantity
-
def
/%(that: BigDecimal): (Money, Money)
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
- that
BigDecimal
- returns
(Money, Money)
-
def
/%(that: Money): (Double, Money)
- Definition Classes
- Quantity
-
def
/%(that: Double): (Money, Money)
- Definition Classes
- Quantity
-
def
<(that: Money): Boolean
- Definition Classes
- Ordered
- def <#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
def
<=(that: Money): Boolean
- Definition Classes
- Ordered
- def <=#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def ==#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
def
=~(that: Money)(implicit tolerance: Money): Boolean
approx
approx
- Definition Classes
- Quantity
-
def
>(that: Money): Boolean
- Definition Classes
- Ordered
- def >#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
def
>=(that: Money): Boolean
- Definition Classes
- Ordered
- def >=#(that: Money)(implicit moneyContext: MoneyContext): Boolean
-
def
abs: Money
Returns the absolute value of this Quantity
- val amount: BigDecimal
-
def
approx(that: Money)(implicit tolerance: Money): Boolean
Returns boolean result of approximate equality comparison
Returns boolean result of approximate equality comparison
- that
Quantity
- tolerance
Quantity
- Definition Classes
- Quantity
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
ceil: Money
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
- Definition Classes
- Quantity
- See also
java.lang.Math#ceil(double)
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
compare(that: Money): Int
Override for Quantity.compare to only work on Moneys of like Currency
-
def
compareTo(that: Money): Int
- Definition Classes
- Ordered → Comparable
- val currency: Currency
-
def
dimension: Money.type
The Dimension this quantity represents
-
def
divide(that: Money): Double
Override for Quantity.divide to only work on Moneys of like Currency Cross currency subtractions should use moneyMinus
-
def
divide(that: Double): Money
Divide this quantity by some number
-
def
divideAndRemainder(that: Money): (Double, Money)
Returns a Pair that includes the result of divideToInteger and remainder
Returns a Pair that includes the result of divideToInteger and remainder
- that
Quantity
- returns
(Double, Quantity)
- Definition Classes
- Quantity
-
def
divideAndRemainder(that: Double): (Money, Money)
Returns a Pair that includes the result of divideToInteger and remainder
Returns a Pair that includes the result of divideToInteger and remainder
- that
Double
- returns
(Quantity, Quantity)
- Definition Classes
- Quantity
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(that: Any): Boolean
Override for Quantity.equal to only match Moneys of like Currency
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
floor: Money
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
- Definition Classes
- Quantity
- See also
java.lang.Math#floor(double)
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
Override of hashCode
Override of hashCode
- Definition Classes
- Quantity → AnyRef → Any
-
def
in(unit: Currency)(implicit context: MoneyContext): Money
Reboxes this Money value in a Money in the given Currency
Reboxes this Money value in a Money in the given Currency
- unit
Currency
- context
MoneyContext required for cross currency operations
- returns
Money
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
-
def
in(uom: UnitOfMeasure[Money]): Money
Returns an equivalent Quantity boxed with the supplied Unit
Returns an equivalent Quantity boxed with the supplied Unit
- uom
UnitOfMeasure[A]
- returns
Quantity
- Definition Classes
- Quantity
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map(f: (Double) ⇒ Double): Money
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
- f
Double => Double function
- Definition Classes
- Quantity
-
def
max(that: Money): Money
Override for Quantity.max to only work on Moneys of like Currency
-
def
min(that: Money): Money
Override for Quantity.max to only work on Moneys of like Currency
-
def
minus(that: Money): Money
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
- that
Money
- returns
Money
- Definition Classes
- Money → Quantity
- Exceptions thrown
scala.UnsupportedOperationException
when attempted on cross currencies
-
def
moneyCompare(that: Money)(implicit moneyContext: MoneyContext): Int
Supports compare operation on Moneys of dislike Currency
Supports compare operation on Moneys of dislike Currency
- that
Money
- moneyContext
MoneyContext
-
def
moneyDivide(that: Money)(implicit context: MoneyContext): BigDecimal
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
- that
Money
- context
MoneyContext
-
def
moneyEquals(that: Money)(implicit moneyContext: MoneyContext): Boolean
Supports equality comparisons on Moneys of dislike Currency
Supports equality comparisons on Moneys of dislike Currency
- that
Money
- moneyContext
MoneyContext
-
def
moneyMax(that: Money)(implicit moneyContext: MoneyContext): Money
Supports max operation on Moneys of dislike Currency
Supports max operation on Moneys of dislike Currency
- that
Money
- moneyContext
MoneyContext
-
def
moneyMin(that: Money)(implicit moneyContext: MoneyContext): Money
Supports min operation on Moneys of dislike Currency
Supports min operation on Moneys of dislike Currency
- that
Money
- moneyContext
MoneyContext
-
def
moneyMinus(that: Money)(implicit context: MoneyContext = defaultMoneyContext): 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
- that
Money
- context
MoneyContext required for cross currency operations
- returns
Money
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
-
def
moneyNotEquals(that: Money)(implicit moneyContext: MoneyContext): Boolean
Supports non-equality comparisons on Moneys of dislike Currency
Supports non-equality comparisons on Moneys of dislike Currency
- that
Money
- moneyContext
MoneyContext
-
def
moneyPlus(that: Money)(implicit context: MoneyContext = defaultMoneyContext): 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
- that
Money
- context
MoneyContext required for cross currency operations
- returns
Money
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
negate: Money
Returns the negative value of this Quantity
-
def
notWithin(range: QuantityRange[Money]): Boolean
Returns true if this value is not within (contains) the range
Returns true if this value is not within (contains) the range
- range
QuantityRange
- returns
Boolean
- Definition Classes
- Quantity
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
plus(that: Money): Money
Overrides Quantity.plus to only work on like currencies.
Overrides Quantity.plus to only work on like currencies. Cross currency additions should use moneyPlus
- that
Money
- returns
Money
- Definition Classes
- Money → Quantity
- Exceptions thrown
scala.UnsupportedOperationException
when attempted on cross currencies
-
def
plusOrMinus(that: Money): QuantityRange[Money]
Returns a QuantityRange representing the range for this value +- that
Returns a QuantityRange representing the range for this value +- that
- that
Quantity
- returns
QuantityRange
- Definition Classes
- Quantity
-
def
remainder(that: Money): Double
Returns the remainder of a division by a like quantity
Returns the remainder of a division by a like quantity
- that
Quantity
- returns
Double
- Definition Classes
- Quantity
-
def
remainder(that: Double): Money
Returns the remainder of a division by a number
Returns the remainder of a division by a number
- that
Quantity
- returns
Quantity
- Definition Classes
- Quantity
-
def
rint: Money
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
- Definition Classes
- Quantity
- See also
java.lang.Math#rint(double)
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
times(that: Double): Money
Multiply this quantity by some number
-
def
to(unit: Currency)(implicit context: MoneyContext): BigDecimal
Convert this Money to a Double representing the currency unit
Convert this Money to a Double representing the currency unit
- unit
Currency
- context
MoneyContext required for cross currency operations
- returns
Double
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
-
def
to(uom: UnitOfMeasure[Money]): Double
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)
- uom
UnitOfMeasure[A]
- returns
Double
- Definition Classes
- Quantity
-
def
to(that: Money): QuantityRange[Money]
Returns a QuantityRange that goes from this to that
Returns a QuantityRange that goes from this to that
- that
Quantity
- returns
QuantityRange
- Definition Classes
- Quantity
- def toFormattedString(c: Currency)(implicit context: MoneyContext): String
-
def
toFormattedString: String
Returns a string formatted with the value and currency symbol
Returns a string formatted with the value and currency symbol
eg USD(100) => "$100.00"
- returns
String
- def toString(c: Currency)(implicit context: MoneyContext): String
-
def
toString(): String
Returns a string formatted with the value and currency code
-
def
toString(uom: UnitOfMeasure[Money], format: String): String
Returns a string representing the quantity's value in the given
unit
in the givenformat
Returns a string representing the quantity's value in the given
unit
in the givenformat
- uom
UnitOfMeasure[A] with UnitConverter
- format
String containing the format for the value (ie "%.3f")
- returns
String
- Definition Classes
- Quantity
-
def
toString(uom: UnitOfMeasure[Money]): String
Returns a string representing the quantity's value in the given
unit
Returns a string representing the quantity's value in the given
unit
- uom
UnitOfMeasure[A] with UnitConverter
- returns
String
- Definition Classes
- Quantity
-
def
toThe(that: Money): CurrencyExchangeRate
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)
- that
Money
- Exceptions thrown
scala.IllegalArgumentException
if the that.currency matches this.currency
-
def
toTuple(uom: UnitOfMeasure[Money]): (Double, String)
Returns a pair representing the numeric value and the uom's symbol
Returns a pair representing the numeric value and the uom's symbol
- uom
UnitOfMeasure[A]
- Definition Classes
- Quantity
-
def
toTuple: (Double, String)
Returns a tuple representing the numeric value and the unit's symbol
Returns a tuple representing the numeric value and the unit's symbol
- Definition Classes
- Quantity
-
def
unary_-(): Money
- Definition Classes
- Quantity
-
def
unit: Currency
The Unit of Measure the value represents
-
def
value: Double
The value of the quantity given the unit
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
within(range: QuantityRange[Money]): Boolean
Returns true if this value is within (contains) the range
Returns true if this value is within (contains) the range
- range
QuantityRange
- returns
Boolean
- Definition Classes
- Quantity
-
def
~=(that: Money)(implicit tolerance: Money): Boolean
approx
approx
- Definition Classes
- Quantity
-
def
≈(that: Money)(implicit tolerance: Money): Boolean
approx
approx
- Definition Classes
- Quantity