|
Final | |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||
java.lang.Objectjava.lang.Number
java.math.BigDecimal
BigDecimal objects represent an arbitrary precisioned decimal Number. They contain values that cannot be changed. Thus, most operations on the BigDecimal object yield new instances of BigDecimal.
BigDecimal is respresented by an unscaled BigInteger value and an integer representing the scale of the object. The scale of the BigDecimal is the number of digits after the decimal point. Eg. 1.234 would have a scale of 3 and an unscaled value of 1234. Therefore, decimal representation of a BigDecimal is BigIntegerValue/10^scale.
BigInteger,
Serialized Form| Field Summary | |
|---|---|
static int |
ROUND_CEILING
|
static int |
ROUND_DOWN
|
static int |
ROUND_FLOOR
|
static int |
ROUND_HALF_DOWN
|
static int |
ROUND_HALF_EVEN
|
static int |
ROUND_HALF_UP
|
static int |
ROUND_UNNECESSARY
|
static int |
ROUND_UP
Rounding mode Constants |
| Constructor Summary | |
|---|---|
BigDecimal(BigInteger bval)
Constructs a BigDecimal with unscaled value initialized as bval and scale as 0. |
|
BigDecimal(BigInteger bval,
int sc)
Constructs a BigDecimal with unscaled value initialized as bval and scale as scale from the argument. |
|
BigDecimal(double bval)
Constructs a BigDecimal with a double value as an arugment. |
|
BigDecimal(String val)
Constructs a BigDecimal from the strong which can only contan digits of 0-9, a decimal point and a negative sign. |
|
| Method Summary | |
|---|---|
BigDecimal |
abs()
Answers the absolute value of this BigDecimal. |
BigDecimal |
add(BigDecimal bval)
Answers the sum of the receiver and argument. |
int |
compareTo(BigDecimal bval)
Compares the receiver BigDecimal and argument BigDecimal e.x 1.00 & 1.0 will return 0 in compareTo. |
int |
compareTo(Object o)
Compares an receiver to the argument Object. |
BigDecimal |
divide(BigDecimal bval,
int roundingMode)
Answers the result of (this / val). |
BigDecimal |
divide(BigDecimal bval,
int bscale,
int roundingMode)
Answers the result of (this / val) and whose scale is specified. |
double |
doubleValue()
Converts this BigDecimal to a double. |
boolean |
equals(Object obj)
Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. |
float |
floatValue()
Converts this BigDecimal to a float.If magnitude of the BigDecimal value is larger than what can be represented by a float, either Infinity or -Infinity is returned. |
int |
hashCode()
Answers an integer hash code for the receiver. |
int |
intValue()
Converts this BigDecimal to an int. |
long |
longValue()
Converts this BigDecimal to a long. |
BigDecimal |
max(BigDecimal bval)
Answers the max value between the receiver and this BigDecimal. |
BigDecimal |
min(BigDecimal bval)
Answers the min value between the receiver and argument. |
BigDecimal |
movePointLeft(int n)
Moves the decimal point of this BigDecimal n places to the left. |
BigDecimal |
movePointRight(int n)
Moves the decimal point of this BigDecimal n places to the right. |
BigDecimal |
multiply(BigDecimal bval)
Answers the multiplication result of the receiver and argument. |
BigDecimal |
negate()
Negates this BigDecimal value. |
int |
scale()
Returns the scale of this BigDecimal. |
BigDecimal |
setScale(int newScale)
Sets the scale of this BigDecimal. |
BigDecimal |
setScale(int newScale,
int roundingMode)
Sets the scale of this BigDecimal. |
int |
signum()
Answers the signum function of this instance. |
BigDecimal |
subtract(BigDecimal bval)
Answers the subtract result of the receiver and argument. |
BigInteger |
toBigInteger()
Converts this to a BigInteger. |
String |
toString()
Answers a string containing a concise, human-readable description of the receiver. |
BigInteger |
unscaledValue()
Returns an unscaled value of this BigDecimal. |
static BigDecimal |
valueOf(long bval)
Translate long value into a BigDecimal with scale of zero. |
static BigDecimal |
valueOf(long bval,
int scale)
Translate long unscaled value into a BigDecimal specified by the scale. |
| Methods inherited from class java.lang.Number |
|---|
byteValue, shortValue |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int ROUND_UP
public static final int ROUND_DOWN
public static final int ROUND_CEILING
public static final int ROUND_FLOOR
public static final int ROUND_HALF_UP
public static final int ROUND_HALF_DOWN
public static final int ROUND_HALF_EVEN
public static final int ROUND_UNNECESSARY
| Constructor Detail |
public BigDecimal(BigInteger bval)
public BigDecimal(BigInteger bval,
int sc)
public BigDecimal(double bval)
NumberFormatException - If the is Infinity, Negative Infinity or NaN.public BigDecimal(String val)
NumberFormatException - If the argument contained characters other than digits.| Method Detail |
public BigDecimal abs()
public BigDecimal add(BigDecimal bval)
public int compareTo(Object o)
compareTo in interface Comparableo - Object
an object to compare the receiver to
ClassCastException - if the argument is not of type BigDecimalpublic int compareTo(BigDecimal bval)
public BigDecimal divide(BigDecimal bval,
int roundingMode)
public BigDecimal divide(BigDecimal bval,
int bscale,
int roundingMode)
ArithmeticException - division by zero.
IllegalArgumentException - roundingMode is not valid.public double doubleValue()
doubleValue in class Numberpublic boolean equals(Object obj)
Object
equals in class Objectobj - Object
the object to compare with this object.
true
if the object is the same as this object
false
if it is different from this object.Object.hashCode()public float floatValue()
floatValue in class Numberpublic int hashCode()
true when passed to
.equals must answer the same value for this
method.
hashCode in class Objectequals(Object)public int intValue()
intValue in class Numberpublic long longValue()
longValue in class Numberpublic BigDecimal max(BigDecimal bval)
public BigDecimal min(BigDecimal bval)
public BigDecimal movePointLeft(int n)
public BigDecimal movePointRight(int n)
public BigDecimal multiply(BigDecimal bval)
public BigDecimal negate()
public int scale()
public BigDecimal setScale(int newScale)
public BigDecimal setScale(int newScale,
int roundingMode)
ArithmeticException - rounding mode must be specified if lose of precision due to setting scale.
IllegalArgumentException - invalid rounding modepublic int signum()
public BigDecimal subtract(BigDecimal bval)
public BigInteger toBigInteger()
public String toString()
toString in class Objectpublic BigInteger unscaledValue()
public static BigDecimal valueOf(long bval)
public static BigDecimal valueOf(long bval,
int scale)
NumberFormatException - the scale value is < 0;
|
Final | |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||