I was reading BigDecimal Class but I was not able to find any information how BigDecimal
class stores values in computer memory.
Do you know any reliable source that can provide this information?
I was reading BigDecimal Class but I was not able to find any information how BigDecimal
class stores values in computer memory.
Do you know any reliable source that can provide this information?
The unscaled value of the BigDecimal is stored in a BigInteger. The precision and scale are stored separately in integer fields:
BigInteger intVal
int scale
int precision
BigInteger stores the integer as a big-endian array of 32 bit integers, and the sign separately as another 32-bit integer.
int signum
int[] mag
But as Muhd says, if the number can fit in a 64 bit integer, then this is used instead of a BigInteger.
The significant digits of the number are stored in a long if the number of digits is sufficient to be fit in a long, otherwise they are stored in a BigInteger. In addition, BigDecimal has int primitives to represent the scale and precision, scale indicating the number of significant digits right of the decimal point, and precision indicating the number of significant digits total in the number.