📌  相关文章
📜  Java中的短floatValue()方法与示例

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

Java中的短floatValue()方法与示例

Short 类的Java.lang.Short.floatValue()方法是Java中的内置方法,用于将 Short 对象的值作为浮点数返回。

句法:

public float floatValue()

返回类型:它以float形式返回 ShortObject 的值。

下面是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