Saturday, July 17, 2004

Bankers' Rounding

I came across Eric Lippert's blog again today, and (oh joy!) was reminded of a brilliant post of his that sorted out some rounding issues we had with MS Access 2000 for a payroll system where we had not accounted for VBA's wonderful Bankers' Rounding anomaly*.

Microsoft Knowledgebase article #196652 explains rounding in even more detail - but is less clear if read first.

The actual solution we used was based on Eric Bachtal's very elegant VBA rounding solution (it's a nice explanation with a solution using only 3 lines of code).

* The 'anomaly' (or rather undocumented feature) is that when VBA rounds a .5 it rounds to the nearest even number above that decimal place - up or down. This leads to weird effects when you expect a bunch of numbers to round in the more 'normal' fashion, and find they don't.


  1. Ok. You need to cease the Lippert discipleship, burn access, realise that Microsoft was never made to do anything vaguely intelligent like not round numbers. Can you imagine what the airline industry woudl be like if it was run by Gates? Landings are optional, take-offs require a engine feature patch and in-flight service is limited to your ability to speak machine code. The stewards don't know anything else.

    Access! That is an oxymoron!

  2. Well, I certainly wouldn't want a blue screen of death mid-flight!

    OTOH, do we really want everything to cost twice as much and come in any colour you want ... except black or beige? :->

    Seriously though, Microsoft's great strength has been their attractiveness as a platform for software developers, and their ability to be all things for all people. I actually developed on a cross-platform Mac/Windows tool a decade ago, and it wasn't obviously not a good career move.

    Apple are the Pepsi to Microsoft's Coca-Cola, they will always have a place in the market, and in some areas they may upset the apple-cart (pun intended), but they won't (and probably don't) want to take over the world.