<<< The RoundingMode and scale | Index | RoundingMode.HALF_EVEN >>> |
Rounding means discarding a fraction of the value.
The RoundingMode.HALF_UP rounding mode is the one commonly taught at school:
if the discarded fraction is >= 0.5, round up;
if the discarded fraction is < 0.5, then round down.
For example, after
BigDecimal bdRounded = bdValue.setScale(0, RoundingMode.HALF_UP);
the rounding will be
Input Rounded value ----- ------------- 4.5 -> 5 1.1 -> 1
The zero parameter sets the precision scale to zero decimal points.
<<< The RoundingMode and scale | Index | RoundingMode.HALF_EVEN >>> |