<-- Previous || Up || Next -->

Round To Precision Function
Math Reals Class

Public Function RoundToPrecision( _
      ByVal vNumber As Variant _
    , Optional ByVal vPrecision As Variant _
    ) As Variant

Round the number vNumber to the nearest vPrecision.

Examples:
    RoundToPrecision(45.3) = 45
    RoundToPrecision(45.5) = 46 ' #2
    RoundToPrecision(45.7) = 46
    RoundToPrecision(-45.7) = -46
    RoundToPrecision(-45.5) = -45 ' #5
    RoundToPrecision(-45.3) = -45
    RoundToPrecision(-45.37, .1) = -45.4
    RoundToPrecision(-12.3456, .01) = -12.35
See also:
    RoundToPrecisionVerify Subroutine
    RoundToDigits Function
    Round Function (Visual Basic)
    Ceiling Function
    Floor Function
    NextNumber Function
    PreviousNumber Function
vNumber: The number that is rounded either up or down to the nearest vPrecision. Function returns Null if vNumber is Null or cannot be fixed up to a number.
Note: When vNumber is exactly half-way between the range the numbers, it is always rounded up, as in examples #2 and #5.

vPrecision: The nearest number to which vNumber is rounded. vPrecision defaults to 1 (zero) if it is missing or Null or cannot be fixed up to a String. With a precision of 1 (one), vNumber will be rounded to the nearest integer; with a precision of .1, vNumber will be rounded to the nearest tenth, etc.

Definition:

    Floor(vNumber / vPrecision + .5) * vPrecision
v1.3 BugFix: This function was returning incorrect results in prior versions of Entisoft Tools. Both the Function and its Definition have been corrected.
v1.5 Change: This function has been renamed from Round to RoundToPrecision, in order to avoid confusion with the new Round Function in Visual Basic 6.0. The Round function in Visual Basic 6.0 is the same as the RoundToDigits Function in Entisoft Tools.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.