Java.lang.Number.floatValue() 方法
描述
java.lang.Number.floatValue() 方法将指定数字的值作为浮点数返回。 这可能涉及舍入或截断。
声明
以下是 java.lang.Number.floatValue() 方法的声明。
public abstract float floatValue()
参数
NA
返回值
该方法返回此对象转换为float类型后所表示的数值。
异常
NA
示例
下面的例子展示了 lang.Number.floatValue() 方法的使用。
package com.tutorialspoint;
public class NumberDemo {
public static void main(String[] args) {
// get a number as integer
Integer x = new Integer(123456);
// get a number as double
Double y = new Double(9876);
// print their value as float
System.out.println("x as integer:" + x
+ ", x as float:" + x.floatValue());
System.out.println("y as double:" + y
+ ", y as float:" + y.floatValue());
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
x as integer:123456, x as float:123456.0 y as double:9876.0, y as float:9876.0

