Class Money
- All Implemented Interfaces:
- BigValue,- Storable,- Comparable<Money>
- Author:
- Syam
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA class representing a list of currency values.
- 
Constructor SummaryConstructorsConstructorDescriptionMoney()Create a monetary value of zero in the default currency.Create a monetary value from the amount specified in a particular currency.Create a monetary value from the amount specified in a particular currency.Create a monetary value from the amount specified in the default currency.Create a monetary value from the amount specified in a particular currency.Create a monetary value from the amount specified in a particular currency.Create a monetary value of zero in a particular currency.Create a monetary value from the amount specified in a particular currency.Create a monetary value from the amount specified in a particular currency.Money(BigDecimal value) Create a monetary value from the amount specified in the default currency.Money(BigDecimal amount, String currencyCode) Create a monetary value from the amount specified in a particular currency.Money(BigDecimal value, Currency currency) Create a monetary value from the amount specified in a particular currency.Create a monetary value of zero in a particular currency.
- 
Method SummaryModifier and TypeMethodDescriptionabsolute()Return the monetary value containing the absolute value.Add amountAdd amount valueadd(BigDecimal amount) Add amountConvert this monetary value to another currency by applying the buying rate.Convert this monetary value to another currency by applying the buying rate.buy(Currency currency, CurrencyRateProvider rateProvider) Convert this monetary value to another currency by applying the buying rate.intConvert this monetary value to another currency (by multiplying with the average rate).Convert this monetary value to another currency (by multiplying with the average rate).convert(Currency currency, CurrencyRateProvider rateProvider) Convert this monetary value to another currency (by multiplying with the average rate).static MoneyConstruct a monetary value from a string representation.currencies(boolean includeMetals) divide(double divisor) Divide the amount with a valueDivide the amount with a rate and convert it to another currency.divide(DecimalNumber divisor) Divide the amount with a ratedivide(DecimalNumber divisor, Currency currency) Divide the amount with a rate and convert it to another currency.Divide the amount with a quantity (To find the unit price)divide(BigDecimal divisor) Divide the amount with a rate.divide(BigDecimal divisor, Currency currency) Divide the amount with a rate and convert it to another currency.booleangetBuyingRate(Date date, Currency currency) Gets the selling rate.static RategetBuyingRate(Date date, Currency currency, SystemEntity systemEntity) Gets the buying rate.static RategetBuyingRate(Date date, Currency from, Currency to) Gets the selling rate.getBuyingRate(Currency currency) Gets the selling rate.static RategetBuyingRate(Currency currency, SystemEntity systemEntity) Gets the buying rate.static RategetBuyingRate(Currency from, Currency to) Gets the selling rate.Get the currency of this monetary value.static CurrencygetCurrency(String code) Get currency for the given code.static CurrencygetCurrency(String code, boolean includeMetals) Get currency for the given code.intGets the number of decimals.static CurrencyGet the default currency.getExchangeRate(Date date, Currency currency) Gets the exchange rate (average of selling rate and buying rate).getExchangeRate(Date date, Currency currency, SystemEntity systemEntity) Gets the exchange rate (average of selling rate and buying rate).static RategetExchangeRate(Date date, Currency from, Currency to) Gets the exchange rate (average of selling rate and buying rate).getExchangeRate(Currency currency) Gets the exchange rate (average of selling rate and buying rate).getExchangeRate(Currency currency, SystemEntity systemEntity) Gets the exchange rate (average of selling rate and buying rate).static RategetExchangeRate(Currency from, Currency to) Gets the exchange rate (average of selling rate and buying rate).intstatic intgetFractionDigits(Currency currency) getSellingRate(Date date, Currency currency) Gets the selling rate.static RategetSellingRate(Date date, Currency currency, SystemEntity systemEntity) Gets the selling rate.static RategetSellingRate(Date date, Currency from, Currency to) Gets the selling rate.getSellingRate(Currency currency) Gets the selling rate.static RategetSellingRate(Currency currency, SystemEntity systemEntity) Gets the selling rate.static RategetSellingRate(Currency from, Currency to) Gets the selling rate.Get the storable value.static StringGet the symbol for the given currency.getValue()Get the monetary value as BigDecimal.inthashCode()booleanisCredit()Checks if this is a credit amount or not.booleanisDebit()Checks if this is a debit amount or not.booleanisGreaterThan(long value) Check if this is greater than 'value'.booleanisGreaterThan(Money another) Check if this is greater than 'another'.booleanisGreaterThanOrEqual(long value) Check if this is greater than or equal to 'value'.booleanisGreaterThanOrEqual(Money another) Check if this is greater than or equal to 'another'.booleanisLessThan(long value) Check if this is less than 'value'.booleanisLessThan(Money another) Check if this is less than 'another'.booleanisLessThanOrEqual(long value) Check if this is less than or equal to 'value'.booleanisLessThanOrEqual(Money another) Check if this is less than or equal to 'another'.static booleanstatic booleanIs the platform running in a multi-currency (and multi-tenancy) environment?booleanbooleanChecks if this is a positive amount or not.booleanisZero()Checks if this is zero or not.multiply(double multiplicand) Multiply the amount with a valueMultiply the amount with a value and convert to another currency.multiply(DecimalNumber multiplicand) Multiply the amount with a ratemultiply(DecimalNumber multiplicand, Currency currency) Multiply the amount with a rate and convert to another currency.Multiply the amount with a quantity (Given the unit price, find out the total amount).multiply(BigDecimal multiplicand) Multiply the amount with a valuemultiply(BigDecimal multiplicand, Currency currency) Multiply the amount with a rate and convert to another currency.negate()Reverses the sign of this money.percentage(double percentage) Calculate the percentage.percentage(DecimalNumber percentage) Calculate the percentage.percentage(Rate percentage) Calculate the percentage.percentage(BigDecimal percentage) Calculate the percentage.round()Round the amount to the lower/upper value.Round the amount to the lower value.roundUp()Round the amount to the upper value.Convert this monetary value to another currency by applying the selling rate.Convert this monetary value to another currency by applying the selling rate.sell(Currency currency, CurrencyRateProvider rateProvider) Convert this monetary value to another currency by applying the selling rate.Subtract amountSubtract amountsubtract(BigDecimal amount) Subtract amounttoLocal(Rate exchangeRate, SystemEntity systemEntity) Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".toLocal(Rate exchangeRate, TransactionManager tm) Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".toLocal(SystemEntity systemEntity) Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".toLocal(Date date, SystemEntity systemEntity) Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".toLocal(Date date, TransactionManager tm) Convert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".toString()Create the formatted representation of the amount value with appropriate decimals places.toString(boolean showSymbol) Create the formatted representation of the amount value with appropriate decimals places.toString(boolean showSymbol, boolean tagDebit) Create the formatted representation of the amount value with appropriate decimals places.toString(boolean showSymbol, boolean tagDebit, SystemUser forUser) Create the formatted representation of the amount value with appropriate decimals places.toString(boolean showSymbol, SystemUser forUser) Create the formatted representation of the amount value with appropriate decimals places.toString(SystemUser forUser) Create the formatted representation of the amount value with appropriate decimals places.booleanWhether a rounding took place when this was created or not.words()Get the currency amount in words.words(boolean camelCase) Get the currency amount in words.words(SystemUser forUser) Get the currency amount in words.words(SystemUser forUser, boolean camelCase) Get the currency amount in words.zero()Set the monetary value to zero.
- 
Constructor Details- 
Moneypublic Money()Create a monetary value of zero in the default currency.
- 
MoneyCreate a monetary value of zero in a particular currency.- Parameters:
- currencyCode- The currency code (ISO standard)
 
- 
Money
- 
MoneyCreate a monetary value from the amount specified in a particular currency.- Parameters:
- amount- The amount
- currencyCode- The currency code (ISO standard)
 
- 
MoneyCreate a monetary value of zero in a particular currency.- Parameters:
- currency- Currency
 
- 
Money
- 
MoneyCreate a monetary value from the amount specified in a particular currency.- Parameters:
- value- The BigDecimal value.
- currency- Currency
 
- 
MoneyCreate a monetary value from the amount specified in a particular currency.- Parameters:
- value- The money value. The value will be rounded (half-way up) if required.
- currency- Currency
 
- 
MoneyCreate a monetary value from the amount specified in a particular currency.- Parameters:
- value- The money value. The value will be rounded (half-way up) if required.
- currencyCode- The currency code (ISO standard)
 
- 
Money
- 
Money
- 
MoneyCreate a monetary value from the amount specified in the default currency.- Parameters:
- value- The amount.
 
- 
MoneyCreate a monetary value from the amount specified in the default currency.- Parameters:
- value- The amount.
 
 
- 
- 
Method Details- 
getDefaultCurrencyGet the default currency. If this is invoked in a multi-currency environment, a runtime exception will be thrown.- Returns:
- Default currency.
 
- 
isMultiCurrencypublic static boolean isMultiCurrency()Is the platform running in a multi-currency (and multi-tenancy) environment? A multi-currency environment is an environment where multiple system entities exist and not all of them have the same accounting currency.- Returns:
- True/false.
 
- 
create
- 
getCurrency
- 
getCurrency
- 
getDecimalspublic int getDecimals()Gets the number of decimals.- Returns:
- Number of decimals
 
- 
getValueGet the monetary value as BigDecimal.
- 
getCurrency
- 
zero
- 
add
- 
addAdd amount- Parameters:
- amount- The amount value to add
- Returns:
- Result
 
- 
add
- 
getBuyingRate
- 
getBuyingRate
- 
getSellingRate
- 
getSellingRate
- 
getExchangeRate
- 
getExchangeRateGets the exchange rate (average of selling rate and buying rate).Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- currency- Currency for which rate is required.
- Returns:
- Rate
 
- 
getBuyingRateGets the buying rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getBuyingRateGets the buying rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getSellingRateGets the selling rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getSellingRateGets the selling rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getExchangeRateGets the exchange rate (average of selling rate and buying rate).Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getExchangeRateGets the exchange rate (average of selling rate and buying rate).Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- currency- Currency for which rate is required.
- systemEntity- System Entity.
- Returns:
- Rate
 
- 
getBuyingRate
- 
getBuyingRateGets the selling rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- from- Currency for which rate is required.
- to- Target currency to convert to.
- Returns:
- Rate
 
- 
getSellingRate
- 
getSellingRateGets the selling rate.Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- from- Currency for which rate is required.
- to- Target currency to convert to.
- Returns:
- Rate
 
- 
getExchangeRateGets the exchange rate (average of selling rate and buying rate).Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- from- Currency for which rate is required.
- to- Target currency to convert to.
- Returns:
- Rate
 
- 
getExchangeRateGets the exchange rate (average of selling rate and buying rate).Note: To convert to the target currency, you need to divide the monetary value with this rate. - Parameters:
- date- Effective date.
- from- Currency for which rate is required.
- to- Target currency to convert to.
- Returns:
- Rate
 
- 
convertConvert this monetary value to another currency (by multiplying with the average rate).- Parameters:
- currency- Currency to convert to.
- rateProvider- Currency rate provider.
- Returns:
- Converted monetary value.
 
- 
convert
- 
convert
- 
buyConvert this monetary value to another currency by applying the buying rate.- Parameters:
- currency- Currency to convert to.
- rateProvider- Currency rate provider.
- Returns:
- Converted monetary value.
 
- 
buy
- 
buy
- 
sellConvert this monetary value to another currency by applying the selling rate.- Parameters:
- currency- Currency to convert to.
- rateProvider- Currency rate provider.
- Returns:
- Converted monetary value.
 
- 
sell
- 
sell
- 
subtract
- 
subtractSubtract amount- Parameters:
- amount- The amount value to subtract
- Returns:
- Result
 
- 
subtract
- 
multiply
- 
multiplyMultiply the amount with a value- Parameters:
- multiplicand- Multiplicand
- Returns:
- Result
 
- 
multiply
- 
multiplyMultiply the amount with a value- Parameters:
- multiplicand- Multiplicand
- Returns:
- Result
 
- 
multiplyMultiply the amount with a rate and convert to another currency.- Parameters:
- multiplicand- Multiplicand
- currency- Currency to convert to.
- Returns:
- Result
 
- 
multiplyMultiply the amount with a rate- Parameters:
- multiplicand- Multiplicand
- Returns:
- Result
 
- 
multiplyMultiply the amount with a rate and convert to another currency.- Parameters:
- multiplicand- Multiplicand
- currency- Currency to convert to.
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- exchangeRate- Exchange rate
- tm- Transaction manager (Local currency will be determined from this)
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- exchangeRate- Exchange rate
- systemEntity- System entity (Local currency will be determined from this)
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- tm- Transaction manager (Local currency will be determined from this)
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- date- Effective date.
- tm- Transaction manager (Local currency will be determined from this)
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- systemEntity- System entity (Local currency will be determined from this)
- Returns:
- Result
 
- 
toLocalConvert this monetary value to the equivalent in local currency by multiplying with the given "exchange rate".- Parameters:
- date- Effective date.
- systemEntity- System entity (Local currency will be determined from this)
- Returns:
- Result
 
- 
percentageCalculate the percentage.- Parameters:
- percentage- Percentage
- Returns:
- Result
 
- 
percentageCalculate the percentage.- Parameters:
- percentage- Percentage
- Returns:
- Result
 
- 
percentageCalculate the percentage.- Parameters:
- percentage- Percentage
- Returns:
- Result
 
- 
percentage
- 
divideDivide the amount with a value- Parameters:
- divisor- Divisor
- Returns:
- Result
 
- 
divide
- 
divideDivide the amount with a rate.- Parameters:
- divisor- Divisor
- Returns:
- Result
 
- 
divideDivide the amount with a rate and convert it to another currency.- Parameters:
- divisor- Divisor
- currency- Currency to convert to.
- Returns:
- Result
 
- 
divideDivide the amount with a rate- Parameters:
- divisor- Divisor
- Returns:
- Result
 
- 
divideDivide the amount with a rate and convert it to another currency.- Parameters:
- divisor- Divisor
- currency- Currency to convert to.
- Returns:
- Result
 
- 
divide
- 
negate
- 
absoluteReturn the monetary value containing the absolute value.- Returns:
- Absolute value
 
- 
roundRound the amount to the lower/upper value. If the decimal part is greater than or equal to 0.5, it will be rounded up, otherwise, it will be rounded down.- Returns:
- Rounded value.
 
- 
roundUp
- 
roundDown
- 
equals
- 
isGreaterThanCheck if this is greater than 'another'.- Parameters:
- another- Value to compare.
- Returns:
- True if this is greater.
 
- 
isGreaterThanpublic boolean isGreaterThan(long value) Check if this is greater than 'value'.- Parameters:
- value- Value to compare.
- Returns:
- True if this is greater.
 
- 
isLessThanCheck if this is less than 'another'.- Parameters:
- another- Value to compare.
- Returns:
- True if this is less.
 
- 
isLessThanpublic boolean isLessThan(long value) Check if this is less than 'value'.- Parameters:
- value- Value to compare.
- Returns:
- True if this is less.
 
- 
isGreaterThanOrEqualCheck if this is greater than or equal to 'another'.- Parameters:
- another- Value to compare.
- Returns:
- True if this is greater than or equal.
 
- 
isGreaterThanOrEqualpublic boolean isGreaterThanOrEqual(long value) Check if this is greater than or equal to 'value'.- Parameters:
- value- Value to compare.
- Returns:
- True if this is greater or equal.
 
- 
isLessThanOrEqualCheck if this is less than or equal to 'another'.- Parameters:
- another- Value to compare.
- Returns:
- True if this is less than or equal.
 
- 
isLessThanOrEqualpublic boolean isLessThanOrEqual(long value) Check if this is less than or equal to 'value'.- Parameters:
- value- Value to compare.
- Returns:
- True if this is less than or equal.
 
- 
isZeropublic boolean isZero()Checks if this is zero or not.- Returns:
- True if zero.
 
- 
isDebitpublic boolean isDebit()Checks if this is a debit amount or not.- Returns:
- True if negative.
 
- 
isNegativepublic boolean isNegative()
- 
isCreditpublic boolean isCredit()Checks if this is a credit amount or not. Same asisPositive().- Returns:
- True if positive.
 
- 
isPositivepublic boolean isPositive()Checks if this is a positive amount or not.- Returns:
- True if positive.
 
- 
hashCode
- 
toString
- 
toStringCreate the formatted representation of the amount value with appropriate decimals places.- Returns:
- The formatted string representation of the amount.
 
- 
toStringCreate the formatted representation of the amount value with appropriate decimals places.- Parameters:
- showSymbol- Determines whether currency symbol should be included or not.
- Returns:
- The formatted string representation of the amount.
 
- 
toStringCreate the formatted representation of the amount value with appropriate decimals places.- Parameters:
- showSymbol- Determines whether currency symbol should be included or not.
- Returns:
- The formatted string representation of the amount.
 
- 
toStringCreate the formatted representation of the amount value with appropriate decimals places.- Parameters:
- showSymbol- Determines whether currency symbol should be included or not.
- tagDebit- Add the "DB" tag for negative (debit) amount or not.
- Returns:
- The formatted string representation of the amount.
 
- 
toStringCreate the formatted representation of the amount value with appropriate decimals places.- Parameters:
- showSymbol- Determines whether currency symbol should be included or not.
- tagDebit- Add the "DB" tag for negative (debit) amount or not.
- forUser- For the user (if non-null, the user's locale country will be used for formatting).
- Returns:
- The formatted string representation of the amount.
 
- 
getSymbol
- 
getStorableValueDescription copied from interface:StorableGet the storable value. By default,Object.toString()is returned.- Specified by:
- getStorableValuein interface- Storable
- Returns:
- Storable value as a string.
 
- 
compareTo- Specified by:
- compareToin interface- Comparable<Money>
 
- 
words
- 
wordsGet the currency amount in words.- Parameters:
- camelCase- Whether to show on a camel-case or not.
- Returns:
- Currency amount in words.
 
- 
wordsGet the currency amount in words.- Parameters:
- forUser- For the user (if non-null, the user's locale country will be used for formatting).
- Returns:
- Currency amount in words.
 
- 
wordsGet the currency amount in words.- Parameters:
- forUser- For the user (if non-null, the user's locale country will be used for formatting).
- camelCase- Whether to show on a camel-case or not.
- Returns:
- Currency amount in words.
 
- 
wasRoundedpublic boolean wasRounded()Whether a rounding took place when this was created or not.- Returns:
- True/false.
 
- 
currencies
- 
currencies
- 
isMetal
- 
getFractionDigitspublic int getFractionDigits()
- 
getFractionDigits
 
-