java.math.
RoundingMode.HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. Behaves as for RoundingMode.UP
if the discarded fraction is ≥ 0.5; otherwise, behaves as for RoundingMode.DOWN
. Note that this is the rounding mode commonly taught at school.
学校里面教的,日常用得最多的是这种模式
Example:
Input Number | Input rounded to one digit with HALF_UP rounding |
---|---|
5.5 | 6 |
2.5 | 3 |
1.6 | 2 |
1.1 | 1 |
1.0 | 1 |
-1.0 | -1 |
-1.1 | -1 |
-1.6 | -2 |
-2.5 | -3 |
-5.5 | -6 |