Java Data Type Tutorial - Java BigDecimal.intValue()








Syntax

BigDecimal.intValue() has the following syntax.

public int intValue()

Example

In the following code shows how to use BigDecimal.intValue() method.

/*from www.j a  v a2  s  .  co m*/
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("1234");

    // assign a larger value to bg2
    BigDecimal bg2 = new BigDecimal("123456789098765");

    // assign the int value of bg1 and bg2 to i1,i2 respectively
    int i1 = bg1.intValue();
    int i2 = bg2.intValue();

    System.out.println(i1);
    System.out.println(i2);
  }
}

The code above generates the following result.