VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Symmetric Arithmetic Rounding (Excel style rounding)

Brian Pierron  (1 Submission)   VB function enhancement   Visual Basic 3.0   Intermediate   Wed 3rd February 2021

The Visual Basic functions CByte(), CInt(), CLng(), CCur() and Round() user a Banker's Rounding algorithm. For example, VBA.Round(0.15,1) = 0.2 **AND** VBA.Round(0.25,1) = 0.2. The following code uses Symmetric Arithmetic Rounding (similar to the Excel Worksheet Round function) where Round(0.15,1) = 0.2 and Round(0.25,1) = 0.3. Also, precision is enhanced by passing the 'Number' parameter as variant and using CDec within the routine. This helps circumvent floating point limitations. To see an excellent resource on different rounding procedures (the basis for this code) see Microsoft Article ID: Q196652.

Rate Symmetric Arithmetic Rounding (Excel style rounding) (2(2 Vote))
Symmetric Arithmetic Rounding (Excel style rounding).bas

Symmetric Arithmetic Rounding (Excel style rounding) Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters