The java.math package, new in Java 1.1, contains
classes for arbitrary-precision integer and floating-point
arithmetic. Arbitrary-length integers are required for
cryptography, and arbitrary-precision floating-point values
are useful for financial applications that need to be
careful about rounding errors. The class hierarchy of this
extremely small package is shown in
Figure 27.1.

This subclass of java.lang.Number represents a
floating-point number of arbitrary size and precision. Its
methods duplicate the functionality of the standard Java
arithmetic operators. The compareTo() method
compares the value of two BigDecimal objects and
returns -1, 0, or 1 to indicate the result of the
comparison.

BigDecimal objects are represented as an integer of
arbitrary size and an integer scale that specifies the
number of decimal places in the value. When working with
BigDecimal values, you can explicitly specify the
amount of precision (the number of decimal places) you are
interested in. Also, whenever a BigDecimal method
may discard precision (in a division operation, for
example), you are required to specify what sort of rounding
should be performed on the digit to the left of the
discarded digit or digits. The eight constants defined by
this class specify the available rounding modes. Because
the BigDecimal class provides arbitrary precision
and gives you explicit control over rounding and the number
of decimal places you are interested in, it can be useful
when dealing with quantities that represent money, or in
other circumstances where the tolerance for rounding errors
is low.