round Java · 数学方法
对浮点数四舍五入取整;float 返回 int,double 返回 long。
怎么用
Math.round(小数)
小例子
System.out.println(Math.round(3.6)); System.out.println(Math.round(3.4));
运行结果
输出: 4 3
提醒:负数四舍五入时向绝对值小的方向取整,例如 Math.round(-1.5) 得到 -1
官方文档:https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Java全部词条