Float类中的floatToRawIntBits()方法是Java中的内置函数,在类型转换后将调用对象指定的值恢复为float。
用法:
public float floatValue()
返回值:它返回FloatObject的值作为float。
以下程序说明了Java中的floatValue()方法:
示例1:
// Java code to demonstrate
// Float floatValue() method
class GFG {
public static void main(String[] args)
{
// Float value
Float a = 17.47f;
// wrapping the Float value
// in the wrapper class Float
Float b = new Float(a);
// floatValue of the Float Object
float output = b.floatValue();
// prfloating the output
System.out.println("Float value of "
+ b + " is : " + output);
}
}
输出:
Float value of 17.47 is : 17.47
示例2:
// Java code to demonstrate
// Float floatValue() method
class GFG {
public static void main(String[] args)
{
String value = "54.1";
// wrapping the Float value
// in the wrapper class Float
Float b = new Float(value);
// floatValue of the Float Object
float output = b.floatValue();
// prfloating the output
System.out.println("Float value of "
+ b + " is : " + output);
}
}
输出:
Float value of 54.1 is : 54.1