java.lang.Byte.floatValue()方法範例


java.lang.Byte.floatValue() 返回此位元組為float的值。

宣告

以下是java.lang.Byte.floatValue()方法的宣告

public float floatValue()

指定

floatValue 在類 Number

引數

  • NA

返回值

此方法將返回該物件轉換後表示為float型別的數值。

異常

  • NA

例子

下面的例子顯示lang.Byte.floatValue()方法的使用。

package com.yiibai;

import java.lang.*;

public class ByteDemo {

   public static void main(String[] args) {

      // create 2 Byte objects b1, b2
      Byte b1, b2;

      // create 2 float primitives f1, f2
      float f1, f2;

      // assign values to b1, b2
      b1 = new Byte("100");
      b2 = new Byte("-10");

      // assign float values of b1, b2 to f1, f2
      f1 = b1.floatValue();
      f2 = b2.floatValue();

      String str1 = "float value of Byte " + b1 + " is " + f1;
      String str2 = "float value of Byte " + b2 + " is " + f2;

      // print f1, f2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

讓我們來編譯和執行上面的程式,這將產生以下結果:

float value of Byte 100 is 100.0
float value of Byte -10 is -10.0