Java Byte floatValue()方法及示例

来源:这里教程网 时间:2026-02-17 20:39:56 作者:

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

相关推荐