The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,509 other followers

.NET uses banker’s rounding as default as it follows IEEE 754 (via: Stack Overflow)

Posted by jpluimers on 2014/05/08

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:

The other answers with reasons why the Banker’s algorithm (aka round half to even) is a good choice are quite correct. It does not suffer from negative or positive bias as much as the round half away from zero method over most reasonable distributions.

But the question was why .NET use Banker’s actual rounding as default – and the answer is that Microsoft has followed the IEEE 754 standard. This is also mentioned in MSDN for Math.Round under Remarks.

Also note that .NET supports the alternative method specified by IEEE by providing the MidpointRounding enumeration. They could of course have provided more alternatives to solving ties, but they choose to just fulfill the IEEE standard.


via: Why does .NET use banker’s rounding as default? – Stack Overflow.

3 Responses to “.NET uses banker’s rounding as default as it follows IEEE 754 (via: Stack Overflow)”

  1. Nicholas Ring said

    I think there is a typo – 3.5 to 5… That is a lot of rounding ;-)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: