Friday, December 17, 2010

VBA and bankers' rounding

Most children learn in elementary school that you round 5 up. That's how Excel works. But the language used to write programs in Excel, Visual Basic for Applications, does not do that with its Round() function. It uses bankers' rounding, which is described by a Microsoft blogger. You can write a custom function such as one here, but that's kind of a hassle.

It's annoying, but there is a workaround: call the Excel Round function, as described by this guy.

If VBA was open-source, I imagine that this would have been fixed a while ago. Regular round would be Round(), and Bankers' round would be Bankround() or something. VBA seems like a mess.

No comments: