Scale and precision

ReturnMethodSummary
intprecision()Returns the precision.
intscale()Returns the scale.
BigDecimalsetScale(int newScale)Change the scale.
BigDecimalsetScale(int newScale, int roundingMode)Set scale with rounding Mode.
BigDecimalsetScale(int newScale, RoundingMode roundingMode)Set scale with rounding Mode.
intsignum()Returns the signum function of this BigDecimal.
BigIntegerunscaledValue()Get the unscaled value.
BigDecimalulp()Returns the size of an ulp(a unit in the last place).

import java.math.BigDecimal;
 

public class Main {
 
    public static void main(String[] args) {
        BigDecimal first = new BigDecimal(10f);
        System.out.println(first);
        System.out.println(first.precision());
        System.out.println(first.setScale(3));
    }
}

The output:


10
2
10.000
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.