public class BigDecimal extends Object
BigDecimal
is basically a
BigInteger
with a few digits on the right of
the decimal point. The number of (binary) digits on the right of the decimal
point is called the scale
of the BigDecimal
.
Unlike in BigDecimal
, the scale is not adjusted
automatically, but must be set manually. All BigDecimal
s
taking part in the same arithmetic operation must have equal scale. The
result of a multiplication of two BigDecimal
s returns a
BigDecimal
with double scale.Constructor and Description |
---|
BigDecimal(BigInteger bigInt,
int scale)
Constructor for
BigDecimal . |
Modifier and Type | Method and Description |
---|---|
BigDecimal |
add(BigDecimal b) |
BigDecimal |
add(BigInteger b) |
BigDecimal |
adjustScale(int newScale) |
int |
compareTo(BigDecimal val) |
int |
compareTo(BigInteger val) |
BigDecimal |
divide(BigDecimal b) |
BigDecimal |
divide(BigInteger b) |
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
BigInteger |
floor() |
static BigDecimal |
getInstance(BigInteger value,
int scale)
Returns a
BigDecimal representing the same numerical
value as value . |
int |
getScale() |
int |
hashCode()
Returns a hash code value for the object.
|
int |
intValue() |
long |
longValue() |
BigDecimal |
multiply(BigDecimal b) |
BigDecimal |
multiply(BigInteger b) |
BigDecimal |
negate() |
BigInteger |
round() |
BigDecimal |
shiftLeft(int n) |
BigDecimal |
subtract(BigDecimal b) |
BigDecimal |
subtract(BigInteger b) |
String |
toString()
Returns a string representation of the object.
|
public BigDecimal(BigInteger bigInt, int scale)
BigDecimal
. The value of the
constructed BigDecimal
equals bigInt /
2scale
.bigInt
- The bigInt
value parameter.scale
- The scale of the constructed BigDecimal
.public static BigDecimal getInstance(BigInteger value, int scale)
BigDecimal
representing the same numerical
value as value
.value
- The value of the BigDecimal
to be
created.scale
- The scale of the BigDecimal
to be
created.BigDecimal
.public BigDecimal adjustScale(int newScale)
public BigDecimal add(BigDecimal b)
public BigDecimal add(BigInteger b)
public BigDecimal negate()
public BigDecimal subtract(BigDecimal b)
public BigDecimal subtract(BigInteger b)
public BigDecimal multiply(BigDecimal b)
public BigDecimal multiply(BigInteger b)
public BigDecimal divide(BigDecimal b)
public BigDecimal divide(BigInteger b)
public BigDecimal shiftLeft(int n)
public int compareTo(BigDecimal val)
public int compareTo(BigInteger val)
public BigInteger floor()
public BigInteger round()
public int intValue()
public long longValue()
public int getScale()
public String toString()
Object
public boolean equals(Object o)
Object
public int hashCode()
Object