输出例子如下:
Math.round(-1.4)=-1
Math.round(-1.5)=-1Math.round(-1.6)=-2
Math.round(1.4)=1
Math.round(1.5)=2
Math.round(1.6)=2
Math.floor(-1.6)=-2.0
Math.floor(-1.5)=-2.0
Math.floor(-1.4)=-2.0
Math.floor(1.6)=1.0
Math.floor(1.5)=1.0
Math.floor(1.4)=1.0
总结:1.round相当于四舍五入 ,但负数-1.5“四舍五入”后等于-1;
2.floor对于相当于返回比x(参数)小的 最大的整数。
本文详细解析了Java中Math类的round与floor函数的工作原理及应用实例。round函数实现四舍五入效果,而floor函数则返回不大于参数的最大整数值。文中通过具体示例展示了两种函数对正负数的不同处理方式。
102

被折叠的 条评论
为什么被折叠?



