BigDecimal.intValueExact() has the following syntax.
public int intValueExact()
In the following code shows how to use BigDecimal.intValueExact() method.
//w w w. ja va 2 s .c o m import java.math.BigDecimal; public class Main { public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("40"); BigDecimal bg2 = new BigDecimal("4E+1"); // assign the exact int value of bg1 and bg2 to i1,i2 respectively int i1 = bg1.intValueExact(); int i2 = bg2.intValueExact(); // print i1,i2 values System.out.println(i1); System.out.println(i2); } }
The code above generates the following result.