setScale

open override fun setScale(newScale: Int, roundingMode: RoundingMode): BigDecimal

Returns a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value. If the _scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Return

a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value.

Since

1.5

Parameters

newScale

_scale of the BigDecimal value to be returned.

roundingMode

The rounding mode to apply.

See also

Throws

if roundingMode==UNNECESSARY and the specified scaling operation would require rounding.


open override fun setScale(newScale: Int): BigDecimal

Returns a BigDecimal whose _scale is the specified value, and whose value is numerically equal to this BigDecimal's. Throws an ArithmeticException if this is not possible.

This call is typically used to increase the _scale, in which case it is guaranteed that there exists a BigDecimal of the specified _scale and the correct value. The call can also be used to reduce the _scale if the caller knows that the BigDecimal has sufficiently many zeros at the end of its fractional part (i.e., factors of ten in its integer value) to allow for the rescaling without changing its value.

This method returns the same result as the two-argument versions of setScale, but saves the caller the trouble of specifying a rounding mode in cases where it is irrelevant.

Return

a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value.

Parameters

newScale

_scale of the BigDecimal value to be returned.

See also

.setScale

Throws

if the specified scaling operation would require rounding.


open override fun setScale(newScale: Int, roundingMode: Int): BigDecimal

Deprecated

The method {@link #setScale(int, RoundingMode)} should be used in preference to this legacy method.

Returns a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value. If the _scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Return

a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value.

Parameters

newScale

_scale of the BigDecimal value to be returned.

roundingMode

The rounding mode to apply.

See also

.ROUND_UNNECESSARY

Throws

if roundingMode==ROUND_UNNECESSARY and the specified scaling operation would require rounding.

if roundingMode does not represent a valid rounding mode.