Class MoneyUtil
java.lang.Object
com.commercetools.api.models.common.MoneyUtil
Utility methods to convert from
MonetaryAmount to Money and vice versa-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longamountToCents(javax.money.MonetaryAmount monetaryAmount) static longamountToPreciseAmount(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static CentPrecisionMoneyBuilderbuilder(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoneyBuilderbuilder(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static javax.money.MonetaryAmountcalculateAppliedTaxes(TaxedItemPrice taxedPrice) Calculates the taxes applied to the pricing.static javax.money.MonetaryAmountcalculateGrossPrice(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the gross price of the given amount according to its tax rate.static javax.money.MonetaryAmountcalculateNetPrice(javax.money.MonetaryAmount amount, TaxRate taxRate) Calculates the net price of the given amount according to its tax rate.static javax.money.MonetaryAmountconvertGrossToNetPrice(javax.money.MonetaryAmount grossAmount, double taxRate) Converts the given gross amount (i.e.static javax.money.MonetaryAmountconvertNetToGrossPrice(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 CentPrecisionMoneyDraftdraftOf(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoneyDraftdraftOf(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static CentPrecisionMoneyof(javax.money.MonetaryAmount monetaryAmount) static HighPrecisionMoneyof(javax.money.MonetaryAmount monetaryAmount, int fractionDigits) static javax.money.MonetaryAmountstatic javax.money.MonetaryAmountstatic javax.money.MonetaryAmountstatic javax.money.MonetaryAmountstatic javax.money.MonetaryAmounttoMonetaryAmount(Money money) static javax.money.MonetaryAmounttoMonetaryAmount(TypedMoney money) static javax.money.MonetaryAmounttoMonetaryAmount(TypedMoneyDraft money) static javax.money.MonetaryAmountzeroAmount(String currency) static javax.money.MonetaryAmountzeroAmount(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.19for 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.19for 19% tax- Returns:
- the net monetary amount
-