Java Data Type Tutorial - Java BigDecimal.longValue()








Syntax

BigDecimal.longValue() has the following syntax.

public long longValue()

Example

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

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

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.67");
    BigDecimal bg2 = new BigDecimal("1234567890987654");

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

    System.out.println(l1);
    System.out.println(l2);
  }
}

The code above generates the following result.