Groovy - rint()
方法 rint 返回与参数值最接近的整数。
语法
double rint(double d)
参数
d - 它接受一个双精度值作为参数。
返回值
此方法返回值最接近参数的整数。 以双精度形式返回。
示例
以下是该方法的用法示例 −
class Example {
static void main(String[] args){
double d = 100.675;
double e = 100.500;
double f = 100.200;
System.out.println(Math.rint(d));
System.out.println(Math.rint(e));
System.out.println(Math.rint(f));
}
}
当我们运行上面的程序时,会得到下面的结果 −
101.0 100.0 100.0

