manzur said:
bart
If zero or positive, the scale is the number of digits to the right
of the decimal point. If negative, the unscaled value of the number is
multiplied by ten to the power of the negation of the scale. The value
of the number represented by the BigDecimal is therefore (unscaledValue
× 10-scale).
So i think that there is no need to set the scale explicitly for
positive numbers and the dividend in my code is also positive.
The "zero or positive" refers the scale, not the number.
BigDecimal.valueOf(10000000.0) is equivalent to new BigDecimal("1.0E7")
and so has scale -6, unscaled value 10.
Using a double literal in BigDecimal valueOf is equivalent to conversion
of the string representation of the literal to a double, conversion of
the double to a String, and construction of a BigDecimal from that
String. There is a risk of rounding errors, as well as unintended scaling.
Unless there is some specific reason to involve doubles, I generally
find it better to stick to direct construction from a String:
new BigDecimal("10000000")
Patricia