Java BigDecimal.longValueExact()

Syntax

BigDecimal.longValueExact() has the following syntax.

public long longValueExact()

Example

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


/*w w  w. j a  v  a2 s .  c o  m*/

import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal(
        "-999999");
    BigDecimal bg2 = new BigDecimal("3.3E+10");

    // assign the long value of bg1 and bg2 to l1,l2 respectively
    long l1 = bg1.longValueExact();
    long l2 = bg2.longValueExact();

    // print l1,l2 values
    System.out.println(l1);
    System.out.println(l2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger