case class Money(amount: BigDecimal, currency: Currency)(implicit converter: Converter) extends Ordered[Money] with Product with Serializable
This is the main class of the lib. A Money is represented by its amount
and currency
.
- amount
the amount of this money
- currency
the currency for this money
- Since
2014-10-27
- Alphabetic
- By Inheritance
- Money
- Serializable
- Serializable
- Product
- Equals
- Ordered
- Comparable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
!==(that: Money): Boolean
Converts
that
money tothis
currency and then compares the resulting amounts.Converts
that
money tothis
currency and then compares the resulting amounts.
IMPORTANT NOTE: It's consistency is the one explained in thecompare
method.- that
the other
Money
object- returns
true if
this
!==that
, false otherwise
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
*(thatAmount: BigDecimal): Money
Multiplies amount by this money.
Multiplies amount by this money.
- thatAmount
the amount to multiply by this money
- returns
a new object which is the result of multiplying amount to this money
-
def
+(that: BigDecimal): Money
Adds amount to this money.
Adds amount to this money.
- that
the amount to sum to this money
- returns
a new object which is the result of summing amount to this money
-
def
+(that: Money): Money
Adds this money to
that
.Adds this money to
that
. The result is expressed in terms of this money's currency.- that
the money to sum to this money
- returns
a new object which is the result of summing this money to that after converting that to this money's currency
-
def
-(that: BigDecimal): Money
Subtracts amount from this money.
Subtracts amount from this money.
- that
the amount to sum to this money
- returns
a new object which is the result of summing amount to this money
-
def
-(that: Money): Money
Subtracts
that
from this money.Subtracts
that
from this money. The result is expressed in terms of this money's currency.- that
the money to subtract from this money
- returns
a new object which is the result of subtracting that from this money after converting that to this money's currency
-
def
/(thatAmount: BigDecimal): Money
Divides amount by this money.
Divides amount by this money.
- thatAmount
the amount to multiply by this money
- returns
a new object which is the result of multiplying amount to this money
-
def
<(that: Money): Boolean
- Definition Classes
- Ordered
-
def
<=(that: Money): Boolean
- Definition Classes
- Ordered
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
===(that: Money): Boolean
Converts
that
money tothis
currency and then compares the resulting amounts.Converts
that
money tothis
currency and then compares the resulting amounts.
IMPORTANT NOTE: It's consistency is the one explained in thecompare
method.- that
the other
Money
object- returns
true if
this
===that
, false otherwise
-
def
>(that: Money): Boolean
- Definition Classes
- Ordered
-
def
>=(that: Money): Boolean
- Definition Classes
- Ordered
- val amount: BigDecimal
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
compare(that: Money): Int
Converts
that
money tothis
currency and then compares the amounts.Converts
that
money tothis
currency and then compares the amounts.
IMPORTANT NOTE: Be careful when usingcompare
since it might seem inconsistent because if the conversion rate from, say, EUR to USD is 1.13 it's not guaranteed that the one from USD to EUR is exactly 1 / 1.13 (i.e. the inverse). For this reason, for example, you could have:100(EUR).compare(113(USD)) > 0 == true // (1) // but 113(USD).compare(100(EUR)) < 0 == false // (2)
This is because
that
is first converted tothis
currency and then the resulting amounts are compared. The rule is as simple as the outer left currency is the base one into which all other currencies are converted within an expression. In the previous example (1) 113 USD is converted to EUR and then compared to 100 EUR. In example (2) it's 100 EUR that is converted to USD and then compared. Since the conversion rates are not one the inverse of the other you get apparently inconsistent results even if, for the provided conversions, they are consistent.- that
the other
Money
object- returns
an
Int
that is:- < 0 if
this
<that
- > 0 if
this
>that
- 0 if they are equal (after currency conversion, of course)
- < 0 if
- Definition Classes
- Money → Ordered
-
def
compareTo(that: Money): Int
- Definition Classes
- Ordered → Comparable
- val currency: Currency
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
round(decimalDigits: Int, roundingMode: RoundingMode = RoundingMode.HALF_DOWN): Money
Rounds this
Money
to the given number ofdecimalDigits
using the providedroundingMode
Rounds this
Money
to the given number ofdecimalDigits
using the providedroundingMode
- decimalDigits
the number of decimal digits to keep
- returns
a new
Money
object whose number of decimal digits isdecimalDigits
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
to(thatCurrency: Currency): Money
Converts this money to another money represented using otherCurrency
Converts this money to another money represented using otherCurrency
- thatCurrency
the currency to convert this money to
- returns
a new object where its currency is expressed in terms of otherCurrency
-
def
toFormattedString(decimalDigits: Int = 5): String
Formats this money object using a number of decimal digits equals to the decimalDigits param, which defaults to 5.
Formats this money object using a number of decimal digits equals to the decimalDigits param, which defaults to 5.
- decimalDigits
the number of decimal digits to include
- returns
a formatted string representing this money object
-
def
toString(): String
- returns
the string representation of this money which has, at most, 5 decimal digits. If you need to customize the number of decimal digits use
toFormattedString
instead
- Definition Classes
- Money → AnyRef → Any
-
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
- @native() @throws( ... )