Java Reference
In-Depth Information
BigDecimal's unscaled value by the appropriate power of ten to maintain
its overall value.
Throws:
1. ArithmeticException if scale is negative, or if roundingMode-
==ROUND_UNNECESSARYandthespecifiedscalingoperationwouldre-
quire rounding. Rounding modes are discussed later in this chapter.
2. IllegalArgumentException if roundingMode does not represent a valid
rounding mode.
Examples of the scaling methods are provided in the context of round-
ing operations later in this chapter.
public BigDecimal setScale(int scale)
Returns a BigDecimal whose scale is the specified value as described for
the previous signature of this method. The call to this method can be used
toreducethescaleiftherearesufficientlymanyzerosattheendofitsfrac-
tional part. This allows the rescaling without loss of precision.
Scale() method
Thescale()methodisusedtoobtainthescaleofaBigDecimalnumber.The
method is documented as follows:
public int scale()
Returns the scale of a BigDecimal as a type int.
BigDecimal point operations
Decimal point motion operations are provided by the methods
movePointLeft() and movePointRight(). Both methods return a
BigDecimalcreatedfromtheoperandbymovingthedecimalpointaspeci-
fieddistanceinthespecifieddirection.Thesemethodschangethevalueof
a number without affecting its precision.
public BigDecimal movePointLeft(int n)
Returns a BigDecimal which is equivalent to the argument with the
decimal point moved n places to the left. If n is non-negative, the method
adds n to the scale. If n is negative, the method is equivalent to
movePointRight(-n).
public BigDecimal movePointRight(int n)
Moves the decimal point the specified number of places to the right. If
this BigDecimal's scale is ³ n , the method subtracts n from the scale; oth-
Search WWH ::




Custom Search