0
Thanks

A few words of thanks would be greatly appreciated.

VBA.VB6 - Rounding Function (greater or less than n digits)





The Round() function provides incorrect rounding the numbers of in the following form:
(2a + 0,5) x 10^-n (Round half down)
By cons, the numbers of the form (2a - 0,5) x 10^-n are usually Round half up.
Author: Patrice33740
For example:

Round(0.15, 1) = 0.2
Round(0.25, 1) = 0.2
Round(0.35, 1) = 0.4
Round(0.45, 1) = 0.4

Rounding function given below does not have this anomaly:

Round(0.15, 1) = 0.2
Round(0.25, 1) = 0.3
Round(0.35, 1) = 0.4
Round(0.45, 1) = 0.5


Private Function Round(ByVal Number, ByVal Decimal)     
      Arrondi = Int(Number * 10 ^ Decimal + 1 / 2) / 10 ^ Decimal     
End Function

0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled « VBA.VB6 - Rounding Function (greater or less than n digits) », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

3 Comments