Java.lang Package Classes

Java Double - floatValue() Method



The java.lang.Double.floatValue() method returns the value of this Double as a float after a narrowing primitive conversion.

Syntax

public float floatValue()

Parameters

No parameter is required.

Return Value

Returns the double value represented by this object converted to type float.

Exception

NA.

Example:

In the example below, the java.lang.Double.floatValue() method returns a Double object after conversion to type float.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Double objects
    Double val1 = 25.2;
    Double val2 = -25.2;

    //printing floatValue of the Double objects
    System.out.println("floatValue of the val1 is: " + val1.floatValue()); 
    System.out.println("floatValue of the val2 is: " + val2.floatValue());   
  }
}

The output of the above code will be:

floatValue of the val1 is: 25.2
floatValue of the val2 is: -25.2

❮ Java.lang - Double