BigDecimal is a numeric object type in Java that represents decimal numbers with arbitrary precision.
Because double
and float
use a fixed amount of memory (64 and 32 bits respectively), they have limited precision which can lead to rounding errors, and more importantly, they cannot be used to represent all decimal fractions exactly as they use two's complement.
BigDecimal
solves these problems by providing arbitrary precision and by using a decimal representation of their values.
The BigDecimal
class also provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.
More information can be found in the BigDecimal Javadoc