Java.lang Package Classes

Java Number - floatValue() Method



The java.lang.Number.floatValue() method returns the value of the specified number as a float, which may involve rounding.

Syntax

public abstract float floatValue()

Parameters

No parameter is required.

Return Value

Returns the numeric value represented by this object after conversion to type float.

Exception

NA.

Example:

In the example below, the java.lang.Number.floatValue() method returns the float value of the given numbers.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating an Integer value
    Integer val1 = 123;

    //creating a Double value
    Double val2 = 55.75;

    //printing the float value of given numbers
    System.out.println("float value of val1: " + val1.floatValue()); 
    System.out.println("float value of val2: " + val2.floatValue());   
  }
}

The output of the above code will be:

float value of val1: 123.0
float value of val2: 55.75

❮ Java.lang - Number