I am working with subtracting two bigDecimal numbers. Going into the subtraction method they both have non-zero precision but the result has precision=0.
To my knowledge a bigDecimal number with a precision of 0 is impossible. Even 0 has a precision of 1.
The precision is the number of digits in the unscaled value. For instance, for the number 123.45, the precision returned is 5.
(see also BigDecimal, precision and scale) .
The area in question:
BigDecimal test = (centerHP.getReal().subtract(inverseScale));
The centerHP.getReal()
returns a bigDecimal that is created from this line
new BigDecimal(Double.toString(center.getReal()))
and for context center.real = -0.79
which is a double.
so it is effectively
new BigDecimal("-0.79")
The inverseScale is simply 1
double scale = 1;
BigDecimal inverseScale = (BigDecimal.ONE.divide(new BigDecimal(Double.toString(scale))));
I expect test to be a bigDecimal with a value of -1.79, the int representation should be -179, with a precision of 3 and a scale of 2. However, immediately following the addition operation in the subtract method in the BigDecimal class, my values are as follows:
and test equals:
Note that all other values are correct, it's only the precision that seems to be wrong.