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

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

    Decimals are mostly used for money; banker’s rounding is common when working with money. Or you could say.

    It is mostly bankers that need the decimal type; therefore it does “banker’s rounding”

    Bankers rounding have the advantage that on average you will get the same result if you:

    • round a set of “invoice lines” before adding them up,
    • or add them up then round the total

    Rounding before adding up saved a lot of work in the days before computers.

    (In the UK when we went decimal banks would not deal with half pence, but for many years there was still a half pence coin and shop often had prices ending in half pence – so lots of rounding)

提交回复
热议问题