當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Short floatValue()用法及代碼示例


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


相關用法


注:本文由純淨天空篩選整理自Sruti Rai大神的英文原創作品 Short floatValue() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。