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

前端 未结 5 1262
一向
一向 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:37

    Probably because it's a better algorithm. Over the course of many roundings performed, you will average out that all .5's end up rounding equally up and down. This gives better estimations of actual results if you are for instance, adding a bunch of rounded numbers. I would say that even though it isn't what some may expect, it's probably the more correct thing to do.

提交回复
热议问题