📌  相关文章
📜  Java中的双floatValue()与示例

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

Java中的双floatValue()与示例

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

句法:

DoubleObject.floatValue()

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

示例 1:

Java
// Java Program to Implement floatValue() Method
// of Double Class
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Creating a Double object
        Double d = new Double(23);
 
        // Typecasting the value using
        // floatValue() method of Double class
        float output = d.floatValue();
 
        // Printing the double value on console
        System.out.println(output);
    }
}


Java
// Java Program to Implement floatValue() Method
// of Double Class
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Taking a double value by
        // creating object of Double class
        Double d = new Double(-1023.15);
 
        // Typecasting the value using
        // floatValue() method of Double class
        float output = d.floatValue();
 
        // Printing the above double value
        System.out.println(output);
    }
}


输出:

示例 2:

Java

// Java Program to Implement floatValue() Method
// of Double Class
 
// Class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Taking a double value by
        // creating object of Double class
        Double d = new Double(-1023.15);
 
        // Typecasting the value using
        // floatValue() method of Double class
        float output = d.floatValue();
 
        // Printing the above double value
        System.out.println(output);
    }
}

输出: