rint() 方法返回一个最接近的int、long型值。
该方法有以下几种语法格式:
long round(double d) int round(float f)
d -- double 或 float 的原生数据类型
f -- float 原生数据类型
返回一个最接近的int、long型值,方法会指定返回的数据类型。
public class Test{
public static void main(String args[]){
double d = 100.675;
double e = 100.500;
float f = 100;
float g = 90f;
System.out.println(Math.round(d));
System.out.println(Math.round(e));
System.out.println(Math.round(f));
System.out.println(Math.round(g));
}
}
编译以上程序,输出结果为:
101 101 100 90
在线实例
字符集 & 工具
最新更新
站点信息
Java Number类