Java Data Type Tutorial - Java Number.longValue()








Syntax

Number.longValue() has the following syntax.

public abstract long longValue()

Example

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

//  w  ww.  ja  va  2 s  .c o  m
public class Main {

   public static void main(String[] args) {

      // get a number as float
      Number x = new Float(123456f);

      // get a number as double
      Number y = new Double(9876);

      // print their value as long
      System.out.println("x as float:" + x
              + ", x as long:" + x.longValue());
      System.out.println("y as double:" + y
              + ", y as long:" + y.longValue());

   }
}

The code above generates the following result.