@Immutable
public class Money
extends java.lang.Object
Constructor and Description |
---|
Money(java.math.BigDecimal amount,
java.lang.String currencyCode)
Creates a new Money instance.
|
Modifier and Type | Method and Description |
---|---|
static long |
amountToCents(java.math.BigDecimal centAmount) |
static java.math.BigDecimal |
centsToAmount(double centAmount) |
static java.math.BigDecimal |
centsToAmount(long centAmount) |
static Money |
createFromCentAmount(long centAmount,
java.lang.String currencyCode) |
boolean |
equals(java.lang.Object o) |
java.lang.String |
format(int decimalPlaces)
Formats the amount to given number of decimal places.
|
java.math.BigDecimal |
getAmount()
The exact amount as BigDecimal, useful for implementing e.g.
|
long |
getCentAmount()
The cent amount.
|
java.lang.String |
getCurrencyCode()
The ISO 4217 currency code, for example "EUR" or "USD".
|
int |
hashCode() |
Money |
multiply(double multiplier)
Returns a new Money instance that has the amount multiplied by given factor.
|
Money |
multiply(double multiplier,
java.math.RoundingMode roundingMode)
Returns a new Money instance that has the amount multiplied by given factor.
|
Money |
plus(Money amount)
Returns a new Money instance that is a sum of this instance and given instance.
|
java.lang.String |
toString() |
public Money(java.math.BigDecimal amount, java.lang.String currencyCode)
@Nonnull public java.lang.String getCurrencyCode()
@Nonnull public java.math.BigDecimal getAmount()
@Nonnull public long getCentAmount()
public static Money createFromCentAmount(long centAmount, java.lang.String currencyCode)
@Nonnull public Money plus(Money amount)
@Nonnull public Money multiply(double multiplier, java.math.RoundingMode roundingMode)
@Nonnull public Money multiply(double multiplier)
public java.lang.String format(int decimalPlaces)
price.format(2) => "3.50"
public java.lang.String toString()
toString
in class java.lang.Object
public static long amountToCents(java.math.BigDecimal centAmount)
@Nonnull public static java.math.BigDecimal centsToAmount(long centAmount)
@Nonnull public static java.math.BigDecimal centsToAmount(double centAmount)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object