遇到四舍五入成整数不知道怎么做:用Math.
介绍java中四舍五入函数的用法
1.Math.ceil()
2.Math.floor()
3.Math.round()
1.Math.ceil()
向上舍入,将数值向上舍入为最接近的整数;如3.4舍入为4.0,3.6也舍入为4.0
在这里插入图片描述
2.Math.floor()
向下舍入,将数值向下舍入为最接近的整数;如3.4舍入为3.0,3.6舍入为3.0
在这里插入图片描述
3.Math.round()(最常用的算法)
执行标准舍入,将数值四舍五入为最接近的整数,即我们平时使用的方法,如3.4舍入为3,3.5、3.6舍入为4