java.lang包的Integer类的java.lang.Integer.floatValue()方法用于在扩展原始转换后将给定Integer的值转换为float类型。
用法:
public float floatValue()
参数:该方法不接受任何参数。
返回值:该方法将其转换为float类型后,返回此对象表示的数值。
以下程序说明了java.lang.Integer.floatValue()方法:
示例1:
// 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
示例2:
// 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