Convert double and long to BigDecimal
static BigDecimal valueOf(double val)
- Translates a double into a BigDecimal.
static BigDecimal valueOf(long val)
- Translates a long value into a BigDecimal with a scale of zero.
static BigDecimal valueOf(long unscaledVal, int scale)
- Translates a long unscaled value and an int scale into a BigDecimal.
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
System.out.println(BigDecimal.valueOf(1.00001));
}
}
The output:
1.00001
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