Class MoneyUtil
java.lang.Object
com.commercetools.api.models.common.MoneyUtil
Utility methods to convert from
MonetaryAmount
to Money
and vice versa-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
amountToCents
(javax.money.MonetaryAmount monetaryAmount) static long
amountToPreciseAmount
(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static CentPrecisionMoneyBuilder
builder
(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoneyBuilder
builder
(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static javax.money.MonetaryAmount
calculateAppliedTaxes
(TaxedItemPrice taxedPrice) Calculates the taxes applied to the pricing.static javax.money.MonetaryAmount
calculateGrossPrice
(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the gross price of the given amount according to its tax rate.static javax.money.MonetaryAmount
calculateNetPrice
(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the net price of the given amount according to its tax rate.static javax.money.MonetaryAmount
convertGrossToNetPrice
(javax.money.MonetaryAmount grossAmount, double taxRate) Converts the given gross amount (i.e.static javax.money.MonetaryAmount
convertNetToGrossPrice
(javax.money.MonetaryAmount netAmount, double taxRate) Converts the given net amount (i.e.draftBuilder
(javax.money.MonetaryAmount monetaryAmount) draftBuilder
(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static CentPrecisionMoneyDraft
draftOf
(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoneyDraft
draftOf
(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static CentPrecisionMoney
of
(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoney
of
(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static javax.money.MonetaryAmount
static javax.money.MonetaryAmount
static javax.money.MonetaryAmount
static javax.money.MonetaryAmount
static javax.money.MonetaryAmount
toMonetaryAmount
(Money money) static javax.money.MonetaryAmount
toMonetaryAmount
(TypedMoney money) static javax.money.MonetaryAmount
toMonetaryAmount
(TypedMoneyDraft money) static javax.money.MonetaryAmount
zeroAmount
(String currency) static javax.money.MonetaryAmount
zeroAmount
(javax.money.CurrencyUnit currency)
-
Constructor Details
-
MoneyUtil
public MoneyUtil()
-
-
Method Details
-
toMonetaryAmount
-
toMonetaryAmount
-
toMonetaryAmount
-
toMonetaryAmount
-
toMonetaryAmount
-
toMonetaryAmount
-
toMonetaryAmount
-
zeroAmount
-
zeroAmount
public static javax.money.MonetaryAmount zeroAmount(javax.money.CurrencyUnit currency) -
of
-
of
-
draftOf
-
draftOf
public static HighPrecisionMoneyDraft draftOf(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) -
builder
-
builder
public static HighPrecisionMoneyBuilder builder(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) -
draftBuilder
public static CentPrecisionMoneyDraftBuilder draftBuilder(javax.money.MonetaryAmount monetaryAmount) -
draftBuilder
public static HighPrecisionMoneyDraftBuilder draftBuilder(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) -
amountToCents
public static long amountToCents(javax.money.MonetaryAmount monetaryAmount) -
amountToPreciseAmount
public static long amountToPreciseAmount(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) -
calculateAppliedTaxes
Calculates the taxes applied to the pricing.- Parameters:
taxedPrice
- the items taxed price- Returns:
- the monetary amount
-
calculateGrossPrice
public static javax.money.MonetaryAmount calculateGrossPrice(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the gross price of the given amount according to its tax rate. Whether the provided amount is already gross or net is determined by the tax rate.- Parameters:
amount
- the monetary amounttaxRate
- the tax rate used for calculating the gross price- Returns:
- the monetary amount
-
calculateNetPrice
public static javax.money.MonetaryAmount calculateNetPrice(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the net price of the given amount according to its tax rate. Whether the provided amount is already net or gross is determined by the tax rate.- Parameters:
amount
- the monetary amounttaxRate
- the tax rate corresponding to theamount
- Returns:
- the net monetary amount
-
convertNetToGrossPrice
public static javax.money.MonetaryAmount convertNetToGrossPrice(javax.money.MonetaryAmount netAmount, double taxRate) Converts the given net amount (i.e. without taxes) to gross (i.e. with taxes included) according to the provided tax rate.- Parameters:
netAmount
- the net monetary amounttaxRate
- the given tax rate, e.g.0.19
for 19% tax- Returns:
- the gross monetary amount
-
convertGrossToNetPrice
public static javax.money.MonetaryAmount convertGrossToNetPrice(javax.money.MonetaryAmount grossAmount, double taxRate) Converts the given gross amount (i.e. with taxes included) to net (i.e. without taxes) according to the provided tax rate.- Parameters:
grossAmount
- the gross monetary amounttaxRate
- the given tax rate, e.g.0.19
for 19% tax- Returns:
- the net monetary amount
-