It is almost 3 years that Ostemar wrote an interesting answer on Stack Overflow to the question
Why does .NET use banker’s rounding as default? – Stack Overflow.
Few people (even many programmers don’t!) know about rounding and how it can influence software, let alone what bankers rounding does so lets set a few things straight first.
Rounding matters. Depending on the kinds of software you write, it matters a little, or a lot.
For instance, in these categories, it can matter an awful lot:
- Financial applications
- Statistical applications
Bankers rounding means rounding half even. Which means that #.5 will round to the even number closest to #.
In bankers rounding, 1.5 rounds to 2, 3.5 to 4 as does 4.5, -1.5 rounds to -2, -3.5 to -4 as does -4.5.
This is called “unbiased” because for reasonable distributions of y values, the expected (average) value of the rounded numbers is the same as that of the original numbers.
This is contrary to what the majority of people are accustomed to: Round half away from zero is taught in most countries (even for the Dutch, despite the alias “Dutch Rounding” for round half to even).
Round half away from zero rounds 1.5 rounds to 2, 3.5 to 4 and 4.5 to 5. Negative numbers round like this: -1.5 rounds to -2, -3.5 to -4 as does -4.5 to -5.
This is only free of overall bias if the original numbers are positive or negative with equal probability.
In short, .NET uses bankers rounding because it follows the IEEE 754 rounding rules.
This was his answer: Read the rest of this entry »