Java BigDecimal.intValueExact()

Syntax

BigDecimal.intValueExact() has the following syntax.

public int intValueExact()

Example

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


/*www.  j a v  a2  s  .com*/

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.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger