ホーム 暮らし [Simulation] Banker's Rounding

[Simulation] Banker's Rounding

篠原 沙世 篠原 沙世 • 更新: • 公開: • 読了約 8 分
目次

We will explain and verify "Banker's Rounding," a special rounding method also known as round half to even.

What is "Banker's Rounding"?

n5e71cb1fc8ff

"Banker's Rounding" is a method where if the fraction is less than 0.5, it is rounded down; if it is greater than 0.5, it is rounded up; and if it is exactly 0.5, it is rounded to the nearest even number.
Let's look at some examples.

Examples:
 1.32 → 1 (Same as standard rounding)
 1.52 → 2 (Same as standard rounding)
 1.50 → 2 (Rounded to even)
 2.52 → 3 (Same as standard rounding)
 2.50 → 2 (Rounded to even)

The 2.50 → 2 part differs from standard rounding. Because it rounds to the nearest even number when the fraction is exactly 0.5, "Banker's Rounding" is sometimes called "round half to even."

Simulation

It is said that "Banker's Rounding" suppresses the accumulation of errors caused by rounding compared to standard rounding (hence the name, as bankers preferred to use it).
We compared the degree of error accumulation with standard rounding.

Simulation Overview:
Generate a fixed number of values in the format X.X between 1 and 10, and compare:
 ・The standard average
 ・The average after rounding each value using standard rounding
 ・The average after rounding each value using "Banker's Rounding"

Below are the table and graph showing the simulation results.

Conclusion

As can be seen from the regression line in the graph,
standard rounding maintains a constant number of significant digits regardless of the number of values generated,
while Banker's Rounding results in a higher number of significant digits as the number of generated values increases.
It seems fair to say that "Banker's Rounding has less error accumulation."

Excel and Full VBA Code

This is the Excel file used for this simulation.

The following is the full VBA code.

Option Explicit

Sub main()
   Dim row As Long
   Dim i As Currency

   Dim numberRange As Range
   Dim trueValueRange As Range
   Dim sumRoundRange As Range
   Dim sumBankersRange As Range

   Set numberRange = Range("NUMBER")
   Set trueValueRange = Range("TRUE_VALUE")
   Set sumRoundRange = Range("SUM_ROUND")
   Set sumBankersRange = Range("SUM_BANKERS")

   Dim randomFigure As Double

   Dim sumTrueValue As Currency
   Dim sumRound As Currency
   Dim sumBankers As Currency

   row = 1
   Do While numberRange(row)
       sumTrueValue = 0
       sumRound = 0
       sumBankers = 0

       For i = 1 To numberRange(row)
           randomFigure = RndFigure

           sumTrueValue = sumTrueValue + randomFigure
           sumRound = sumRound + WorksheetFunction.Round(randomFigure, 0)
           sumBankers = sumBankers + Round(randomFigure, 0)
       Next i

       trueValueRange(row) = sumTrueValue / numberRange(row)
       sumRoundRange(row) = sumRound / numberRange(row)
       sumBankersRange(row) = sumBankers / numberRange(row)

       row = row + 1
   Loop
End Sub

Function RndFigure() As Double
   Randomize

   RndFigure = WorksheetFunction.Round(10 * Rnd, 1)
End Function

―――――End of article―――――
Thank you for reading!

同じカテゴリの記事

篠原 沙世

アニメとゲームの新作情報を担当。制作会社・配信元の公式告知と登壇情報を照合して記事化します。

おすすめの関連記事