方法rint返回值最接近参数的整数。
句法
- double rint(double d)
参数
d - 它接受一个double值作为参数。
返回值
此方法返回值最接近参数的整数。 返回为双精度。
例子
下面是一个使用这个方法的例子 -
- 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
转载本站内容时,请务必注明来自W3xue,违者必究。