Java Data Type Tutorial - Java Number.intValue()








Syntax

Number.intValue() has the following syntax.

public abstract int intValue()

Example

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

public class Main {
//from   w w  w  .  j  av a2  s.  c  om
   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 int
      System.out.println("x as float:" + x
              + ", x as Integer:" + x.intValue());
      System.out.println("y as double:" + y
              + ", y as Integer:" + y.intValue());

   }
}

The code above generates the following result.