What is Banker's Rounding?
👉 Banker's rounding (also called round half to even) is a way to round numbers that are exactly halfway between two possibilities.
Instead of always rounding 0.5 up like traditional rounding, in banker's rounding:
If the number is exactly halfway, it rounds to the nearest even number.
This method helps avoid rounding bias, which is important when you’re dealing with large sets of financial numbers (like banks and accountants do).
Simple Examples with Two Decimal Points
- 2.15 → rounded to 2.2 (Because 5 is halfway, and 2.2 is even.)
- 2.25 → rounded to 2.2 (Because 5 is halfway, and 2.2 is even.)
- 2.35 → rounded to 2.4 (Because 5 is halfway, and 2.4 is even.)
- 2.45 → rounded to 2.4 (Because 5 is halfway, and 2.4 is even.)
Notice:
- 2.15 → 2.2 (because 2.2 is even)
- 2.25 → 2.2 (because 2.2 is even)
If the digit before the 5 is even, it stays; if it's odd, it rounds up to make it even.
C# Code Example
In C#, you can use Math.Round with MidpointRounding.ToEven — and this is the default behavior!
Here’s a simple C# example:
using System;
class Program
{
static void Main()
{
double[] numbers = { 2.15, 2.25, 2.35, 2.45, 3.15, 3.25, 3.35 };
foreach (var number in numbers)
{
double rounded = Math.Round(number, 1); // Default uses MidpointRounding.ToEven
Console.WriteLine($"{number} -> {rounded}");
}
}
}
Output:
- 2.15 -> 2.2
- 2.25 -> 2.2
- 2.35 -> 2.4
- 2.45 -> 2.4
- 3.15 -> 3.2
- 3.25 -> 3.2
- 3.35 -> 3.4
If you want to be explicit:
double result = Math.Round(2.25, 1, MidpointRounding.ToEven);
Console.WriteLine(result); // Output: 2.2
Quick Note:
- MidpointRounding.ToEven = Banker's rounding ✅
- MidpointRounding.AwayFromZero = Always round 0.5 up ❌ (not Banker's rounding)
In short:
Banker's rounding helps avoid systematic rounding errors by rounding 0.5 values toward the nearest even number.
No comments: