java.lang.Integer floatValue()

Description :

This java tutorial shows how to use the floatValue() method of Integer class under java.lang package. This method returns the float equivalent of this Integer object. The method floatValue were inherited from Number class.

Method Syntax :

public float floatValue()

Parameter Input :

DataType Parameter Description
N/A N/A N/A

Method Returns :

The floatValue() method simply returns the numeric value represented by this object after conversion to type float.

Compatibility Version :

Requires Java 1.0 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of floatValue() method of Integer class. Basically we ask for user input on the console and then we use the scanner object to get the int input. After that we assign the value to an Integer wrapper class and then get the float equivalent using the floatValue() method of Integer class.

package com.javatutorialhq.java.examples;

import java.util.Scanner;

import static java.lang.System.*;

/*
 * This example source code demonstrates the use of 
 * floatValue() method of Integer class.
 */

public class IntegerFloatValue {

	public static void main(String[] args) {
		// Ask user input
		System.out.print("Enter Desired Value:");
		// declare the scanner object
		Scanner scan = new Scanner(System.in);
		// use scanner to get the value from user console
		int intValue = scan.nextInt();
		// close the scanner object
		scan.close();
		Integer myValue = new Integer(intValue);
		float value = myValue.floatValue();
		out.println("float Value is " + value);

	}

}

Sample Output :

Running the floatValue() method example source code of Integer class will give you the following output

Enter Desired Value:1231
float Value is 1231.0

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :