Java Reference
In-Depth Information
public double doubleValue()
Converts a BigDecimal to a double. If the BigDecimal operand is too large
to represent, the method returns DOUBLE.NEGATIVE_INFINITY or
DOUBLE.POSITIVE_INFINITY.
public float floatValue()
Converts a BigDecimal operand to a float. If the BigDecimal is too large to
represent as a float, the method returns FLOAT.NEGATIVE_INFINITY or
FLOAT.POSITIVE_INFINITY.
public int intValue()
Converts the BigDecimal operand to an int. The fractional part of the
BigDecimalisdiscarded.Iftheresulting“BigInteger”istoolargetofitinan
int, the low-order 32 bits are returned.
public long longValue()
Converts the BigDecimal operand to a long. The fractional part of the
BigDecimal is discarded. If the resulting “BigInteger” is too large to fit in a
long, the low-order 64 bits are returned.
public BigInteger toBigInteger()
ConvertstheBigDecimaloperandtoaBigInteger.Thefractionalpartofthe
BigDecimal is discarded. The BigInteger format is discussed later in this
chapter.
public static BigDecimal valueOf(long unscaledVal, int scale)
Translates a long unscaled value and an int scale into a BigDecimal. This
method is provided in preference to a (long, int) constructor because it al-
lows for reuse of common BigDecimals. For example:
// Testing valueOf()
System.out.println(BigDecimal.valueOf(2, 4)); // 0.0002
public static BigDecimal valueOf(long val)
TranslatesalongvalueintoaBigDecimalwithascaleofzero.Thismethod
isprovidedinpreferencetoa(long)constructorbecauseitallowsforreuse
of common BigDecimals. For example:
// Testing valueOf()
System.out.println(BigDecimal.valueOf(1));
// 1
public String toString()
ReturnsthestringrepresentationoftheBigDecimaloperand.Aleadingmi-
nussignisusedtoindicatesign,andthenumberofdigitstotherightofthe
Search WWH ::




Custom Search