Convert BigDecimal to primitive data types
byte byteValueExact()
- Converts this BigDecimal to a byte, checking for lost information.
double doubleValue()
- Converts this BigDecimal to a double.
float floatValue()
- Converts this BigDecimal to a float.
int intValue()
- Converts this BigDecimal to an int.
int intValueExact()
- Converts this BigDecimal to an int, checking for lost information.
long longValue()
- Converts this BigDecimal to a long.
long longValueExact()
- Converts this BigDecimal to a long, checking for lost information.
short shortValueExact()
- Converts this BigDecimal to a short, checking for lost information.
BigInteger toBigInteger()
- Converts this BigDecimal to a BigInteger.
BigInteger toBigIntegerExact()
- Converts this BigDecimal to a BigInteger, checking for lost information.
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
BigDecimal first = new BigDecimal(-1f);
System.out.println(first.floatValue());
}
}
The output:
-1.0
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