Java Byte floatValue()方法及示例
Byte类的 floatValue() 方法是Java中的一个内置方法,用于将该Byte对象的值作为浮点数返回。
语法
ByteObject.floatValue()
返回值: 它将ByteObject的值作为浮点数返回。
下面是floatValue()方法在Java中的实现。
例1 :
// Java code to demonstrate// Byte floatValue() method class GFG { public static void main(String[] args) { // byte value byte a = 17; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(a); // floatValue of the Byte 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// Byte floatValue() method class GFG { public static void main(String[] args) { String value = "17"; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(value); // floatValue of the Byte Object float output = b.floatValue(); // printing the output System.out.println("Float value of " + b + " is : " + output); }}
输出:
Float value of 17 is : 17.0
