Java Short floatValue()方法及实例
Short类的 java.lang.Short.floatValue() 方法是Java中的一个内置方法,用于将Short对象的值作为浮点数返回。
语法
public float floatValue()
返回类型: 它返回ShortObject的值为 浮点数
下面是floatValue()方法在Java中的实现。
例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
