Rap*_* MM 3 java math decimal rounding digits
我的问题可能看起来很简单,但仍然无法得到有效的东西。我需要自定义 Math.round 舍入格式或其他格式以使其工作如下:
如果数字是 1.6 ,他应该四舍五入到 1 ,如果大于或等于 1.7 ,他应该四舍五入到 2.0 。因此,对于所有其他带有 # .6 的小数结果,我将 1.6 四舍五入为 2 的方式应四舍五入为 1。
我怎样才能做到这一点?
谢谢你!
Arc*_*ord 5
只需这样做:
double threshold = 0.7; Math.round(x - threshold + 0.5);
归档时间:
9 年,10 月 前
查看次数:
883 次
最近记录: