Scale and precision
int precision()
- Returns the precision.
int scale()
- Returns the scale.
BigDecimal setScale(int newScale)
- Change the scale.
BigDecimal setScale(int newScale, int roundingMode)
- Set scale with rounding Mode.
BigDecimal setScale(int newScale, RoundingMode roundingMode)
- Set scale with rounding Mode.
int signum()
- Returns the signum function of this BigDecimal.
BigInteger unscaledValue()
- Get the unscaled value.
BigDecimal ulp()
- 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
Home
Java Book
Essential Classes
Java Book
Essential Classes
BigDecimal:
- BigDecimal class
- Constants for One, Ten and Zero
- Rounding mode
- Create BigDecimals
- Methods used to do calculation
- Convert BigDecimal to primitive data types
- Compare two BigDecimal
- Move decimal point
- Scale and precision
- Convert BigDecimal to String
- Remove the trailing zeros
- Convert double and long to BigDecimal
- Calculating Euler's number e with BigDecimal