public final class MoneyUtils extends Object
MonetaryAmount,
by providing the common functionality. The different explicitly typed methods
are all reduced to methods using BigDecimal as input, hereby
performing any conversion to BigDecimal as needed. Obviosly this
takes some time, so implementors that want to avoid this overhead should
implement MonetaryAmount directly.| Modifier and Type | Method and Description |
|---|---|
static void |
checkAmountParameter(javax.money.MonetaryAmount amount,
javax.money.CurrencyUnit currencyUnit)
Method to check if a currency is compatible with this amount instance.
|
static void |
checkNumberParameter(Number number)
Internal method to check for correct number parameter.
|
static BigDecimal |
getBigDecimal(double num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
static BigDecimal |
getBigDecimal(long num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
static BigDecimal |
getBigDecimal(Number num)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given. |
static BigDecimal |
getBigDecimal(Number num,
javax.money.MonetaryContext moneyContext)
Creates a
BigDecimal from the given Number doing the
valid conversion depending the type given, if a MonetaryContext
is given, it is applied to the number returned. |
static MathContext |
getMathContext(javax.money.MonetaryContext monetaryContext,
RoundingMode defaultMode)
Evaluates the
MathContext from the given MonetaryContext. |
public static BigDecimal getBigDecimal(long num)
BigDecimal from the given Number doing the
valid conversion depending the type given.num - the number typeBigDecimalpublic static BigDecimal getBigDecimal(double num)
BigDecimal from the given Number doing the
valid conversion depending the type given.num - the number typeBigDecimalpublic static BigDecimal getBigDecimal(Number num)
BigDecimal from the given Number doing the
valid conversion depending the type given.num - the number typeBigDecimalpublic static BigDecimal getBigDecimal(Number num, javax.money.MonetaryContext moneyContext)
BigDecimal from the given Number doing the
valid conversion depending the type given, if a MonetaryContext
is given, it is applied to the number returned.num - the number typeBigDecimalpublic static MathContext getMathContext(javax.money.MonetaryContext monetaryContext, RoundingMode defaultMode)
MathContext from the given MonetaryContext.monetaryContext - the MonetaryContextdefaultMode - the default RoundingMode, to be used if no one is set
in MonetaryContext.MathContextpublic static void checkAmountParameter(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currencyUnit)
amount - The monetary amount to be compared to, never null.currencyUnit - the currency unit to compare, never null.javax.money.MonetaryException - If the amount is null, or the amount's CurrencyUnit is not
compatible, meaning has a different value of
CurrencyUnit.getCurrencyCode()).public static void checkNumberParameter(Number number)
number - the number to be checked.IllegalArgumentException - If the number is nullCopyright © 2012-2015 JavaMoney. All Rights Reserved.