|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.billpringle.utils.WrpMoney
public class WrpMoney
Class to encapsullate money values. This class represents money values. The money values are stored internally as BigDecimal variables. All BigDecimal numbers are created using Strings in the constructors to avoid loss of precision if converted to double.
Field Summary | |
---|---|
private java.math.BigDecimal |
amount
the actual amount of money |
private int |
rounding
method of rounding |
private int |
scale
scale - the number of digits right of decimal place |
Constructor Summary | |
---|---|
WrpMoney()
Default constructor |
|
WrpMoney(java.math.BigDecimal val)
Constructor using a BigDecimal value |
|
WrpMoney(java.lang.String val)
Constructor using a string |
Method Summary | |
---|---|
WrpMoney |
add(java.math.BigDecimal val)
Calculate the current value plus the given value This method calculates the sum of the current money value plus the specified amount and returns the result as a new object |
WrpMoney |
add(WrpMoney amt)
Calculate the total of two money values Calculate the sum of this amount and the amount passed. |
void |
decrementBy(WrpMoney amt)
Decrement the money amount by the specified value. |
WrpMoney |
divide(java.math.BigDecimal val)
Divide money amount by specified value This method divides the amount of the current object by the specified value and returns a new object with that value |
WrpMoney |
divide(WrpMoney amt)
Divide the current amount by the specified amount This method will divide the amount of this object by the amount stored in the parameter and return a new object with this amount |
void |
divideBy(java.math.BigDecimal val)
Divide the current amount by the specified value This method divides the amount in the current object with the parameter value and updates the amount to that result |
void |
divideBy(WrpMoney amt)
Divide the current amount by the specified amount This method will divide the amount of the current object with the amount specified in the parameter and udpate the current amount with the result |
java.lang.String |
format()
Format the current amount This method returns a string with the current value formatted for currency. |
java.math.BigDecimal |
getAmount()
|
int |
getRounding()
|
int |
getScale()
|
void |
incrementBy(java.math.BigDecimal val)
Increment the money value by the amount specified This method will increment the internal amount of money by the specified value in the argument |
void |
incrementBy(WrpMoney amt)
Increment the current amount by the specified amount This method increments the money value by the amount stored in the argument |
static void |
main(java.lang.String[] args)
|
WrpMoney |
multiply(java.math.BigDecimal amt)
Multiply the current money amount by the specified value This method will multiply the value of this object by the specified amount and return the result in a new object. |
WrpMoney |
multiply(WrpMoney amt)
Compute the product of two amounts. |
void |
multiplyBy(java.math.BigDecimal val)
Multiply the current money value by the specified value This method multiplies the current money amount by the amount specified in the parameter |
void |
multiplyBy(WrpMoney amt)
Multiply the current amount by the specified amount This method will multiply the money amount of this object by the value stored in the parameter |
void |
setAmount(java.math.BigDecimal amount)
|
void |
setRounding(int rounding)
|
void |
setScale(int scale)
|
WrpMoney |
subtract(java.math.BigDecimal val)
Calculate the difference of two money values This method subtracts the specified amount from the amount of this object and returns a new object with that difference |
WrpMoney |
subtract(WrpMoney amt)
Subtract two money values Calculate the difference between the current amount and the amount passed. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.math.BigDecimal amount
private int scale
private int rounding
Constructor Detail |
---|
public WrpMoney()
public WrpMoney(java.lang.String val) throws java.lang.NumberFormatException
val
- the value of the amount
java.lang.NumberFormatException
public WrpMoney(java.math.BigDecimal val)
val
- the value of the amountMethod Detail |
---|
public WrpMoney add(WrpMoney amt)
amt
- contains the amount to add to this amount
public WrpMoney add(java.math.BigDecimal val)
val
- the value to add
public void incrementBy(WrpMoney amt)
amt
- contains the amount to be addedpublic void incrementBy(java.math.BigDecimal val)
val
- the amount to add to the money amountpublic WrpMoney subtract(WrpMoney amt)
amt
- contains the amount to subtract from this amount
public WrpMoney subtract(java.math.BigDecimal val)
val
- the amount to subtract from the current value
public void decrementBy(WrpMoney amt)
amt
- contains the amount to subtractpublic WrpMoney multiply(WrpMoney amt)
amt
- contains the amount to multiply this by
public WrpMoney multiply(java.math.BigDecimal amt)
amt
- the amount to multiply the amount of this object
public void multiplyBy(WrpMoney amt)
amt
- contains the amount to be multiplied bypublic void multiplyBy(java.math.BigDecimal val)
val
- the amount to multiply this money amountpublic WrpMoney divide(WrpMoney amt)
amt
- amount to divide this money amount by
public WrpMoney divide(java.math.BigDecimal val)
val
- the value to divide by
public void divideBy(WrpMoney amt)
amt
- the amount to divide bypublic void divideBy(java.math.BigDecimal val)
val
- the amount to divide bypublic java.lang.String format()
Note:
Due to the need to convert from BigDecimal to double
when using the NumberFormat Currency methods,
some precision might be lost in the formatted string,
but the actual amount is unaffected.
public java.math.BigDecimal getAmount()
public void setAmount(java.math.BigDecimal amount)
amount
- the amount to setpublic int getScale()
public void setScale(int scale)
scale
- the scale to setpublic int getRounding()
public java.lang.String toString()
toString
in class java.lang.Object
public void setRounding(int rounding)
rounding
- the rounding to setpublic static void main(java.lang.String[] args)
args
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |