|
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
public class 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
Round to positive infinity constant. |
static int |
ROUND_DOWN
Round down constant. |
static int |
ROUND_FLOOR
Round to negative infinity constant. |
static int |
ROUND_HALF_DOWN
Round constant for round to nearest neighbor unless both neighbors are equidistant, then round down. |
static int |
ROUND_HALF_EVEN
Round constant for round to nearest neighbor unless both neighbors are equidistant, then round to the even neighbor. |
static int |
ROUND_HALF_UP
Round constant for round to nearest neighbor unless both neighbors are equidistant, then round up. |
static int |
ROUND_UNNECESSARY
Round constant that will cause an ArithmeticException if rounding is required. |
static int |
ROUND_UP
Round up constant. |
| Constructor Summary | |
|---|---|
BigDecimal(BigInteger bval)
Constructs a BigDecimal with unscaled value initialized from a BigInteger. |
|
BigDecimal(BigInteger bval,
int sc)
Constructs a BigDecimal initialized from a BigInteger with the specified scale. |
|
BigDecimal(double bval)
Constructs a BigDecimal with a double value as an arugment. |
|
BigDecimal(String val)
Constructs a BigDecimal from a string, which can only contain 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 / bval). |
BigDecimal |
divide(BigDecimal bval,
int bscale,
int roundingMode)
Answers the result of (this / bval) 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 a long 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)
bval - the BigInteger value to convert to a BigDecimalpublic BigDecimal(BigInteger bval,
int sc)
bval - the BigInteger value to convert to a BigDecimalsc - the scale used for the resultpublic BigDecimal(double bval)
bval - the double value to convert to a BigDecimal
NumberFormatException - If the is Infinity, Negative Infinity or NaN.public BigDecimal(String val)
val - the String value to convert to a BigDecimal
NumberFormatException - If the argument contained characters other than digits.| Method Detail |
|---|
public BigDecimal abs()
public BigDecimal add(BigDecimal bval)
bval - the BigDecimal to add
public int compareTo(Object o)
compareTo in interface Comparableo - the Object to compare
ClassCastException - if the argument is not of type BigDecimalpublic int compareTo(BigDecimal bval)
bval - the BigDecimal to compare
public BigDecimal divide(BigDecimal bval,
int roundingMode)
bval - the value used to divide the receiverroundingMode - the rounding constant
public BigDecimal divide(BigDecimal bval,
int bscale,
int roundingMode)
bval - the value used to divide the receiverbscale - the scale used for the resultroundingMode - the rounding constant
ArithmeticException - division by zero.
IllegalArgumentException - roundingMode is not valid.public double doubleValue()
doubleValue in class Numberpublic boolean equals(Object obj)
equals in class Objecto - 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.hashCodepublic 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)
bval - the value used to compare
public BigDecimal min(BigDecimal bval)
bval - the value used to compare
public BigDecimal movePointLeft(int n)
n - the number of places to move the decimal point
public BigDecimal movePointRight(int n)
n - the number of places to move the decimal point
public BigDecimal multiply(BigDecimal bval)
bval - the value to multiply with the receiver
public BigDecimal negate()
public int scale()
public BigDecimal setScale(int newScale)
newScale - the scale used for the result
public BigDecimal setScale(int newScale,
int roundingMode)
newScale - the scale used for the resultroundingMode - the rounding constant
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)
bval - the value to subtract from the receiver
public BigInteger toBigInteger()
public String toString()
toString in class Objectpublic BigInteger unscaledValue()
public static BigDecimal valueOf(long bval)
bval - the long value to convert to a BigDecimal
public static BigDecimal valueOf(long bval,
int scale)
bval - the long value to convert to a BigDecimalscale - the scale of the result
NumberFormatException - the scale value is < 0;
|
Final | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||