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 comment:

  1. 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.

    ReplyDelete