Monday, January 22, 2007

*ankers Rounding

I should have known so I'm trying to resist the temptation to throw all my toys out of the pram....

Well, they're all on the floor now so..

You would have thought that even Microsoft couldn't make something so simple as Rounding numbers an exercise in absurdity. At this point, there's a load of programmers looking smug saying "I thought everyone knew that" but as Microsoft choose to a) keep it secret by not documenting it in the help files for the product, and, b) Implement it differently by product I'm going to file them under the category of smug.

What am I stamping my feet about? Well, let's say we want to round .925 to 2 decimal places. What would you expect the answer to be. I'm betting 9.3. Nope, in the Microsoft VB world it's .92

Why? Because they use Bankers Rounding which means "Round to the nearest Even number".

So presumably (because I'm to annoyed to test it) .935 would be rounded up to .94

I'm going to stop now and take a deep breath.

OK, I don't care how they implement it as long as they tell us before we screw up and have to go looking on the Internet for the reason.

For those with anorak tendencies Microsoft KB article 196652 describes the mess.

And for those of you with a nervous disposition just think how many times you have innocently used the Round function...