Short类的java.lang.Short.floatValue()方法是Java中的内置方法,用于将Short对象的值作为浮点数返回。
用法:
public float floatValue()
返回类型:它返回ShortObject的值作为float。
下面是Java中floatValue()方法的实现:
示例1:
// Java code to demonstrate
// Short floatValue() method
class GFG {
public static void main(String[] args)
{
// Short value
Short a = 17;
// wrapping the Short value
// in the wrapper class Short
Short b = new Short(a);
// floatValue of the Short Object
float output = b.floatValue();
// printing the output
System.out.println("Float value of "
+ a + " is : " + output);
}
}
输出:
Float value of 17 is : 17.0
示例2:
// Java code to demonstrate
// Short floatValue() method
class GFG {
public static void main(String[] args)
{
String value = "17";
// wrapping the Short value
// in the wrapper class Short
Short b = new Short(value);
// floatValue of the Short Object
float output = b.floatValue();
// printing the output
System.out.println("Float value of "
+ b + " is : " + output);
}
}
输出:
Float value of 17 is : 17.0