Java.lang Package Classes

Java Number - longValue() Method

The java.lang.Number.longValue() method returns the value of the specified number as a long, which may involve rounding or truncation.


public abstract long longValue()


No parameter is required.

Return Value

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




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

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Float value
    Float val1 = 10.25f;

    //creating a Double value
    Double val2 = 55.75;

    //printing the long value of given numbers
    System.out.println("long value of val1: " + val1.longValue()); 
    System.out.println("long value of val2: " + val2.longValue());   

The output of the above code will be:

long value of val1: 10
long value of val2: 55

❮ Java.lang - Number