· coding  Â· 1 min read

Banker's Rounding

How to be more accurate with decimals

How to be more accurate with decimals

It’s a rounding method that consist if the number before the number to be rounded, is higher than 5, then it wounding up, and if the number before to the number to be round is lower than 5, then rounding down. So far it is simple. The interesting behavior is when the number to be rounded is exactly 5. When it is 5, depends to the number before 5 if it’s even or odd. If it’s even, round down if it’s odd, round up

Or in another words, Round to the even number closer to the number before the 5

In the following table, see the efficacy of the banker’s rounding

Standard RoundingBanker’s Rounding
InterestResultDeviationResultDeviation
0.0050.010.0050-0.005
0.0150.020.0050.020.005
0.0250.030.0050.02-0.005
0.0350.040.0050.040.005
0.0450.050.0050.04-0.005
0.1250.150.0250.120.005

I discovered this because I saw a thread’s post which it said a question about coding. The question was:

Why does this happen?

>>> print(round(6.045))
6.04
>>> print(round(6.035))
6.04

Now you know why. It’s because the default rounding method in Python is the Banker’s Rounding.

Share:
Back to Blog

Related Posts

View All Posts »
A Universe Written by Many

A Universe Written by Many

You Won’t Remember This Title (Or Will You?). Find out what's' behind a good community... and monsters that eat your memories ¿?