📜  Java中的 Double longValue() 示例

📅  最后修改于: 2022-05-13 01:55:19.009000             🧑  作者: Mango

Java中的 Double longValue() 示例

Double 类的longValue()方法是一个内置方法,用于在类型转换后返回调用对象指定的值。

句法

DoubleObject.longValue()

参数:它不接受任何参数。

返回类型:它返回一个long值,即 DoubleObject 的类型转换值。

下面是上述方法的实现。

代码 1:

// Java Code to implement 
// longValue() method of Double class
class GFG {
    // Driver method
    public static void main(String[] args)
    {
  
        // creating a Double object
        Double d = new Double(1022);
  
        // longValue() method of Double class
        // typecast the value
        long output = d.longValue();
  
        // printing the output
        System.out.println(output);
    }
}

输出

1022

代码 2:

// Java Code to implement 
// longValue() method of Double class
class GFG {
    // Driver method
    public static void main(String[] args)
    {
  
        // creating a Double object
        Double d = new Double(-1023.23);
  
        // longValue() method of Double class
        // typecast the value
        long output = d.longValue();
  
        // printing the output
        System.out.println(output);
    }
}

输出

-1023