Java.lang.Float.intValue() Method

Advertisements


Description

The java.lang.Float.intValue() method returns the value of this Float as an int (by casting to type int).

Declaration

Following is the declaration for java.lang.Float.intValue() method

public int intValue()

Parameters

  • NA

Return Value

This method returns the float value represented by this object converted to type int.

Exception

  • NA

Example

The following example shows the usage of java.lang.Float.intValue() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

     /* returns the float value represented by this object
     converted to type int */
     Float obj = new Float("22.10");
     int i = obj.intValue();
     System.out.println("Value = " + i);
    
     obj = new Float("5.0");
     i = obj.intValue();
     System.out.println("Value = " + i);
   }
}   

Let us compile and run the above program, this will produce the following result:

Value = 22
Value = 5



Advertisements
Advertisements