Java.lang Package Classes

Java Float - longValue() Method



The java.lang.Float.longValue() method returns the value of this Float as a long after a narrowing primitive conversion.

Syntax

public long longValue()

Parameters

No parameter is required.

Return Value

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

Exception

NA.

Example:

In the example below, the java.lang.Float.longValue() method returns a Float object after conversion to type long.

import java.lang.*;

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

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

The output of the above code will be:

longValue of the val1 is: 25
longValue of the val2 is: -25

❮ Java.lang - Float