PO Box 6603

Huntsville, AL 35813, USA



Fundamentals: Different Rounding Algorithms

Most people wouldn’t believe the variety of rounding algorithms that can be employed by different applications.

Blog Sponsors

Support My Blog

In many respects, life seemed to be a whole lot simpler when I was a young lad. Take the subject of rounding, for example. If we wanted to round a value like 6.1, 6.2, 6.3, or 6.4 to the nearest whole number, then the answer was 6. Similarly, if we wanted to round 6.6, 6.7, 6.8, or 6.9 to the nearest whole number, then the answer was 7. The only tricky one was the “half-way” value of 6.5, but our teachers told us to round this up to 7, so that’s what we did. “Easy peasy lemon squeezy,” as it were. At that time, I honestly thought that this was all there was to know about rounding. Ah… I was so young, so trusting, and so foolish in those far off days of yore. I’m much wiser (and sadder) now. Over the years, I was introduced to different flavors of rounding, but it wasn’t until I started work on the book How Computers Do Math that I delved deeper into this topic, at which time I discovered how little I knew.
Summary of different rounding algorithms (Click image to see a larger version — Image source: Max Maxfield)
Seriously, most people wouldn’t believe the variety of rounding algorithms that can be employed by different applications. These include round-toward-nearest, round-half-up (arithmetic rounding), round-half-down, round-half-even (banker’s rounding), round-half-odd, round-ceiling (toward positive infinity), round-floor (toward negative-infinity), round-toward-zero, round-away-from-zero, round-up, round-down, truncation (chopping), round-alternate, and round-random (stochastic rounding). Things really get interesting when you start to think about rounding signed binary values, and don’t even start me talking about symmetric versus asymmetric implementations. A big problem is that, even if you understand all this stuff, you really need to pay attention when you are designing hardware or developing software, because different applications may treat things differently. For example, the round method of the Java Math Library provides an asymmetric implementation of the round-half-up algorithm, while the round function in the mathematical modeling, simulation, and visualization tool MATLAB from The MathWorks provides a symmetric implementation. Furthermore, just for giggles and grins, the round function in Visual Basic for Applications 6.0 actually implements the round-half-even (banker’s rounding) algorithm. If you are interested in learning more about all of this, may I be so bold as to point you at my Introduction to Rounding Algorithms, which explains everything in excruciating detail accompanied by lots of lovingly hand-crafted graphics. Also, it may not surprise you to hear that those clever chaps and chappesses at OmniCalculator.com (with 897 free calculators the last time I looked) provide a handy-dandy Rounding Calculator for us to play with:
Rounding Numbers Calculator
The reason I’m waffling on about rounding here is that my chum Jay Dowling just sent me a link to a rather interesting article on The Deadly Consequences of Rounding Errors, which explains how in politics, stock markets, space, and on the battlefield, tiny software calculation mistakes have had enormous consequences. How about you? Have you ever run into a situation where rounding errors caused problems, or where a software application was using a different rounding technique to the one you were expecting?

Blog Sponsors

Support My Blog

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments

Charles Pfeil

Funny, I misread the title and felt that I could get into this one deeply. I thought it said, “Fundamentals: Different Routing Algorithms” Oh well.

Nevertheless, the penny should be banned and every total sale (including taxes) of items should be rounded to the nearest nickel. It will all balance out over time. Prices can remain the same, but when it comes to paying for it, pennies be-gone!

Charles Pfeil

Note that I said it should only be rounded to the nearest nickel AFTER the total sum of the items purchased, plus the total tax. With this method, it doesn’t matter what the individual item prices are. And since it is to the nearest nickel:
1,2 will be rounded down to 0
3,4 will be rounded up to 5
6,7 will be rounded down to 5
8,9 will be rounded up to 10

This could be done automatically at the cash register and since there is no way to accurately price the individual items so that their sum plus the tax of the sum is always 3,4,8 or 9, it will always be random and thus balance out.

I suppose if individual items were always priced such that if only that item was bought plus the tax resulted in a round-up, then the system could be cheated. But what percent of purchases are for only one item? Yes, with a car, an appliance, a house, a yacht, an airplane, the buyer could be cheated out of 2 cents. 🙂

Charles Pfeil

I suppose over time shopkeepers will wonder why they are still using cents in their prices. But one of the tricks they use right now might prevent them from changing prices. It is the .99 trick. Shoppers (the ones with little mathematical inclination) see $5.99 and think $5. So a shopkeeper is more likely to make $5.99 into $5.95.

Maybe the more compelling reason to get rid of pennies is they cost 2.06 cents to make each of them(2018). With 13 billion of them made each year by the U.S. Mint, you would think saving $137 million per year would be meaningful. Oh wait, we are talking about politicians making that kind of decision. Never mind.

Aubrey Kagan

Up here in Canada we recently adopted the model that Charles described. Now it is possible that some shopkeepers made a killing by accumulated many, many cents. However to me it has never felt like price gouging, unlike the decimal conversion in the UK and the EURO upgrade.
I might add that the killing, if there ever was one, has not done much to alleviate the pain many retail outlets are feeling in the face of Internet competition.

Aubrey Kagan

If you need a weight in your pockets to counteract the lift given by your suspenders they are irreplaceable. However as part of a commercial transaction- not so much.

My brother used to travel a lot through Eastern Europe and picked up a lot of loose change that he called “shrapnel”. He stored it in this cookie jar that weighed a ton with all the brass coloured coinage. Until he moved to England and then discovered that the loose change actually had some value.

Aubrey Kagan

AT the risk of lowering the level of levity in this conversation (see what I did there?), I do have some knowledge of suspenders. At the time of my diagnosis, treatment and recovery from tumours in my hip, I could not wear a belt.
I also discovered that in fact I was wearing “braces”. Braces have the clips; suspenders hitch onto buttons on the pants. Another detail from the useless facts that I have stored up in my brain leaving no room for anything useful.


I see problems with rounding all the time in DSP with finite math. To avoid cycling (oscillations) I have to bias the rounding and sometimes delete remainders in the accumulator.

Blog Sponsors

Buy this space!

Recent Posts

Sticking a Finger in Big Brother’s Eye 

Just Call Me a Woodworking Fool 

But Where Should the LEDs Go? 

Kan Klive’s Karnaugh Maps Be Korrect? 

Measuring the Width of a Human Hair with a Laser 

Manual Required for Edison Model 35-A Ticker Tape Machine 

Tension Mounts as Sensor Smackdown Looms 

Meet the DrawBo Robotic Drawing Tutor 

I Can Do Anything Better Than You! 

Make Sure “Only” Knows Its Place 


Already a member? Login

Oops, forgot your password?

Please enter your username or email address.
You will receive a link to create a new password via email.

  • Name

  • Usernames cannot be changed.
  • Contact Info

  • About Yourself

  • Share a little biographical information to fill out your profile. This may be shown publicly.
  • Add or Edit GravatarYou can change your profile picture on Gravatar
  • Type your password.
  • Type your password again.

Edit Profile

You must be logged in to edit your profile.

Would love your thoughts, please comment.x