Package rs.baselib.type
Class MonetaryValue
java.lang.Object
rs.baselib.type.MonetaryValue
- All Implemented Interfaces:
Serializable
,Comparable<MonetaryValue>
A
BigDecimal
configured for monetary operations.
The BigDecimal
is configured with a precision scale of 2, RoundingMode.HALF_UP
.
- Since:
- 1.2.9
- Author:
- ralph
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default scale to be used for monetary valuesstatic final MathContext
TheMathContext
to be used for monetary valuesstatic final RoundingMode
Banker's roundingstatic final MonetaryValue
Deprecated. -
Constructor Summary
ConstructorDescriptionMonetaryValue
(double value) Deprecated.use a specific currencyMonetaryValue(double, Currency)
.MonetaryValue
(double value, Currency currency) Constructor.MonetaryValue
(int value) Deprecated.use a specific currencyMonetaryValue(int, Currency)
.MonetaryValue
(int value, Currency currency) Constructor.MonetaryValue
(long value) Deprecated.use a specific currencyMonetaryValue(long, Currency)
.MonetaryValue
(long value, Currency currency) Constructor.MonetaryValue
(CharSequence value) Deprecated.use a specific currencyMonetaryValue(CharSequence, Currency)
.MonetaryValue
(CharSequence value, Currency currency) Constructor.MonetaryValue
(BigDecimal value) Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency)
.MonetaryValue
(BigDecimal value, RoundingMode roundingMode) Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency, RoundingMode)
.MonetaryValue
(BigDecimal value, RoundingMode roundingMode, MathContext mathContext, int scale) Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency, RoundingMode, MathContext, int)
.MonetaryValue
(BigDecimal value, Currency currency) Constructor.MonetaryValue
(BigDecimal value, Currency currency, RoundingMode roundingMode) Constructor.MonetaryValue
(BigDecimal value, Currency currency, RoundingMode roundingMode, MathContext mathContext, int scale) Constructor.MonetaryValue
(BigInteger value) Deprecated.use a specific currencyMonetaryValue(BigInteger, Currency)
.MonetaryValue
(BigInteger value, Currency currency) Constructor.MonetaryValue
(MonetaryValue value) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(double value) Adds another value to this objectadd
(int value) Adds another value to this objectadd
(long value) Adds another value to this objectadd
(CharSequence value) Adds another value to this objectadd
(BigDecimal value) Adds another value to this objectadd
(BigInteger value) Adds another value to this objectadd
(MonetaryValue value) Adds another value to this objectint
divide
(double value) Divides this object by another value.divide
(int value) Divides this object by another value.divide
(long value) Divides this object by another value.divide
(CharSequence value) Divides this object by another value.divide
(BigDecimal value) Divides this object by another value.divide
(BigInteger value) Divides this object by another value.divide
(MonetaryValue value) Divides this object by another value.boolean
Returns the amount.Returns this value asBigInteger
.Returns the currency.double
Returns this value as a double.float
getFloat()
Returns this value as a float.int
getInt()
Returns this value as int.long
getLong()
Returns this value as a long.Returns theMathContext
.Returns the rounding mode.int
getScale()
Returns the scale.int
hashCode()
boolean
Is value negative?boolean
Is value positive?boolean
isZero()
Is value positive?multiply
(double value) Multiplies another value with this object.multiply
(int value) Multiplies another value with this object.multiply
(long value) Multiplies another value with this object.multiply
(CharSequence value) Multiplies another value with this object.multiply
(BigDecimal value) Multiplies another value with this object.multiply
(BigInteger value) Multiplies another value with this object.negate()
Negates this value.void
setAmount
(BigDecimal amount) Sets the amount.void
setCurrency
(Currency currency) Sets the currency.void
setMathContext
(MathContext mathContext) Sets theMathContext
.void
setRoundingMode
(RoundingMode roundingMode) Sets the rounding mode.void
setScale
(int scale) Sets the scale.subtract
(double value) Subtracts another value from this object.subtract
(int value) Subtracts another value from this object.subtract
(long value) Subtracts another value from this object.subtract
(CharSequence value) Subtracts another value from this object.subtract
(BigDecimal value) Subtracts another value from this object.subtract
(BigInteger value) Subtracts another value from this object.subtract
(MonetaryValue value) Subtracts another value from this object.toString()
The representation of the value as stringstatic MonetaryValue
Creates an amount of zero in the given locale.
-
Field Details
-
ROUNDING_MODE
Banker's rounding -
MATH_CONTEXT
TheMathContext
to be used for monetary values -
DEFAULT_SCALE
public static final int DEFAULT_SCALEThe default scale to be used for monetary values- See Also:
-
ZERO
Deprecated.usezero(Currency)
instead.0
-
-
Constructor Details
-
MonetaryValue
Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency, RoundingMode)
.Constructor.- Parameters:
value
- the monetary valueroundingMode
- the rounding mode to be used
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valueroundingMode
- the rounding mode to be usedcurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
@Deprecated public MonetaryValue(BigDecimal value, RoundingMode roundingMode, MathContext mathContext, int scale) Deprecated.use a specific currencyMonetaryValue(BigDecimal, Currency, RoundingMode, MathContext, int)
.Constructor.- Parameters:
value
- the monetary valueroundingMode
- the rounding mode to be usedmathContext
- theMathContext
to be usedscale
- the scale to be used
-
MonetaryValue
public MonetaryValue(BigDecimal value, Currency currency, RoundingMode roundingMode, MathContext mathContext, int scale) Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)roundingMode
- the rounding mode to be usedmathContext
- theMathContext
to be usedscale
- the scale to be used
-
MonetaryValue
Deprecated.use a specific currencyMonetaryValue(CharSequence, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
public MonetaryValue(double value) Deprecated.use a specific currencyMonetaryValue(double, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
Deprecated.use a specific currencyMonetaryValue(BigInteger, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
public MonetaryValue(int value) Deprecated.use a specific currencyMonetaryValue(int, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
MonetaryValue
public MonetaryValue(long value) Deprecated.use a specific currencyMonetaryValue(long, Currency)
.Constructor.- Parameters:
value
- the monetary value
-
MonetaryValue
Constructor.- Parameters:
value
- the monetary valuecurrency
- the currency (can be null, default is currency of default locale)
-
-
Method Details
-
getAmount
Returns the amount.- Returns:
- the amount
-
setAmount
Sets the amount.- Parameters:
amount
- the amount to set
-
getCurrency
Returns the currency.- Returns:
- the currency
-
setCurrency
Sets the currency.- Parameters:
currency
- the currency (can be null, default is currency of default locale)
-
getRoundingMode
Returns the rounding mode.- Returns:
- the rounding mode
-
setRoundingMode
Sets the rounding mode.- Parameters:
roundingMode
- the rounding mode to set
-
getScale
public int getScale()Returns the scale.- Returns:
- the scale
-
setScale
public void setScale(int scale) Sets the scale.- Parameters:
scale
- the scale to set
-
getMathContext
Returns theMathContext
.- Returns:
- the mathContext
-
setMathContext
Sets theMathContext
.- Parameters:
mathContext
- the mathContext to set
-
isPositive
public boolean isPositive()Is value positive?- Returns:
true
when value is a positive number
-
isNegative
public boolean isNegative()Is value negative?- Returns:
true
when value is a negative number
-
isZero
public boolean isZero()Is value positive?- Returns:
true
when value is a positive number
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
add
Adds another value to this object- Parameters:
value
- value to be added- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
subtract
Subtracts another value from this object.- Parameters:
value
- value to be subtracted- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
multiply
Multiplies another value with this object.- Parameters:
value
- value to be multiplied with- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- new monetary value holding the result
-
divide
Divides this object by another value.- Parameters:
value
- value to be divided by- Returns:
- the result of the operation
-
negate
Negates this value.- Returns:
- new monetary value holding the result
-
getDouble
public double getDouble()Returns this value as a double.- Returns:
- value as double
- See Also:
-
getFloat
public float getFloat()Returns this value as a float.- Returns:
- value as float
- See Also:
-
getInt
public int getInt()Returns this value as int.- Returns:
- value as int
- See Also:
-
getBigInteger
Returns this value asBigInteger
.- Returns:
- value as BigInteger
- See Also:
-
getLong
public long getLong()Returns this value as a long.- Returns:
- value as long
- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<MonetaryValue>
-
hashCode
public int hashCode() -
equals
-
toString
The representation of the value as string -
zero
Creates an amount of zero in the given locale.- Parameters:
currency
- the currency (can be null, default is currency of default locale)- Returns:
- the zero amount.
-
zero(Currency)
instead.