Interchange between BigDecimal and long, int
In the actual development process, BigDecimal is a frequently used data type that can be converted to and from int long.
The conversion relationship is shown in the following code:
int converted to BigDecimal data type
int converted to BigDecimal type
public static void Inttobigdecimal () {
int b = 5;
BigDecimal a = new BigDecimal (b);
The data type of System.out.println (A + "is" +a.getclass (). GetName ());
}
Lont Convert to BigDecimal data type
The Long type is converted into BigDecimal
public static void Longtobigdecimal () {
Long B = 5;
BigDecimal a = new BigDecimal (b);
The data type of System.out.println (A + "is" +a.getclass (). GetName ());
}
BigDecimal Convert to Long data type
BigDecimal Convert to Long type
public static void Bigdecimaltolong () {
BigDecimal B = new BigDecimal (12);
Long C = B.longvalue ();
The data type of SYSTEM.OUT.PRINTLN (c+ "is" +c.getclass (). GetName ());
}
BigDecimal Convert to int data type
BigDecimal Convert to int type
public static void Bigdecimaltoint () {
BigDecimal B = new BigDecimal (12);
int c = B.intvalue ();
}
Category: Java Basics
Tags: long, int, BigDecimal, BigDecimal and int conversions, BigDecimal and long conversions
Convert between BigDecimal and long int