int intValue()
描述 (Description)
java.lang.Float.intValue()方法将此Float的值作为int返回(通过强制转换为int类型)。
声明 (Declaration)
以下是java.lang.Float.intValue()方法的声明
public int intValue()
参数 (Parameters)
NA
返回值 (Return Value)
此方法返回此对象表示的float值,该值转换为int类型。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.Float.intValue()方法的用法。
package com.iowiki;
import java.lang.*;
public class FloatDemo {
public static void main(String[] args) {
/* returns the float value represented by this object
converted to type int */
Float obj = new Float("22.10");
int i = obj.intValue();
System.out.println("Value = " + i);
obj = new Float("5.0");
i = obj.intValue();
System.out.println("Value = " + i);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Value = 22
Value = 5