Why does .NET use banker's rounding as default?

前端 未结 5 1265
一向
一向 2020-11-22 06:30

According to the documentation, the decimal.Round method uses a round-to-even algorithm which is not common for most applications. So I always end up writing a custom functi

5条回答
  •  失恋的感觉
    2020-11-22 06:38

    While I cannot answer the question of "Why did Microsoft's designers choose this as the default?", I just want to point out that an extra function is unnecessary.

    Math.Round allows you to specify a MidpointRounding:

    • ToEven - When a number is halfway between two others, it is rounded toward the nearest even number.
    • AwayFromZero - When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.

提交回复
热议问题