Java Double floatValue()方法及示例
Double类的floatValue()方法是一个内置的方法,用于返回调用对象指定的、经过类型转换后的float值。
语法
DoubleObject.floatValue()
返回类型: 它返回一个 Float 值,即DoubleObject的类型转换值。
例子1 :
// 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);
}
}
输出
例2 :
// 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);
}
}
输出