RoundingMode HALF_EVEN 类似于用于 float 的舍入策略

RoundingMode HALF_EVEN analogous to the rounding policy used for float

RoundingMode.HALF_EVEN 的 javadoc 指出:

This rounding mode is analogous to the rounding policy used for float and double arithmetic in Java.

这句话到底是什么意思? 我只注意到只使用了 HALF_UP,例如 String.format 或十进制格式。

"IEEE Standard for Floating-Point Arithmetic"(Java 数字以其为模型)要求中间结果使用必要的最大精度并在末尾四舍五入到结果宽度。舍入的默认规则是 HALF_EVEN.

https://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules