Java.lang.Byte.floatValue() 方法
描述
java.lang.Byte.floatValue() 将此 Byte 的值作为浮点数返回。
声明
以下是 java.lang.Byte.floatValue() 方法的声明。
public float floatValue()
指定者
floatValue 类 Number
参数
NA
返回值
该方法返回此对象表示的数值转换为float类型后。
异常
NA
示例
下面的例子展示了 lang.Byte.floatValue() 方法的使用。
package com.tutorialspoint;
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

