📌  相关文章
📜  Java中的整数 floatValue() 方法

📅  最后修改于: 2022-05-13 01:55:22.689000             🧑  作者: Mango

Java中的整数 floatValue() 方法

Java .lang 包的Integer 类的Java .lang.Integer.floatValue() 方法用于将给定的Integer 的值在加宽原语转换后转换为float 类型。

句法 :

public float floatValue()

参数:该方法不接受任何参数。

返回值:该方法将该对象转换为float类型后返回的数值。

下面的程序说明了Java.lang.Integer.floatValue() 方法:
方案一:

// Java program to demonstrate working
// of java.lang.Integer.floatValue() method
import java.lang.Integer;
  
class Gfg {
  
    // Driver code
    public static void main(String args[])
    {
        Integer a = new Integer(28);
  
        // Convert Integer number to float value
        float b = a.floatValue();
  
        System.out.println(b);
    }
}
输出:
28.0

方案二:

// Java program to demonstrate working
// of java.lang.Integer.floatValue() method
import java.lang.Integer;
  
class Gfg {
    // Driver code
    public static void main(String args[])
    {
        Integer a = new Integer(20);
  
        // Convert Integer number to float value
        float b = a.floatValue();
  
        System.out.println(b);
    }
}
输出:
20.0