Java Reference
In-Depth Information
decimalpointisusedtoindicatescale.Thismethodiscompatiblewiththe
constructor that uses a String argument.
public int hashCode()
ReturnsthehashcodefortheBigDecimaloperand.Thehashcodeisanin-
teger calculated from the number's value and scale. For this reason two
numbers with the same value but different scales may have different hash
codes. However, it is possible that two unequal big decimal numbers may
havethesamehashcodes.Hashcodesandhashtablesareusedindatapro-
cessing.
BigDecimal rounding controls
Theclassjava.mathcontainsseveralconstantsthatareusedtoenableany
one of several rounding modes. These constants are defined as static field
variablesoftypeintintheBigDecimalclass. Table22-1 liststherounding
mode constants.
Table 22-1
Rounding Mode Constants in BigDecimal Class
CONSTANT
ACTION
ROUND_CEILING Round towards positive infinity
ROUND_DOWN Round towards zero
ROUND_FLOOR Round towards negative infinity
ROUND_HALF_DOWN Round towards nearest value unless
both values are equidistant, in which
case round down
ROUND_HALF_EVEN Round towards the nearest value un-
less both values are equidistant, in
which case, round towards the even
value
ROUND_HALF_UP Round towards nearest value unless
both values are equidistant, in which
case round up
ROUND_UNNECESSARY Assert that the requested operation
hasan exact result, hence no
rounding is necessary
ROUND_UP
Round away from zero
The rounding control constants are typically used in methods that con-
tain a rounding mode parameter, such as the setScale() and divide()
methods of the BigDecimal class. For example, a method to change the
scale and the rounding mode of a BigDecimal variable could be coded as
follows:
 
Search WWH ::




Custom Search