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

Round To Digits Function
Math Reals Class

Public Function RoundToDigits( _
      ByVal vNumber As Variant _
    , Optional ByVal vDigits As Variant _
    ) As Variant

Round the number vNumber to vDigits digits of accuracy.

    RoundToDigits(45.3) = 45
    RoundToDigits(45.5) = 46 ' #2
    RoundToDigits(45.7) = 46
    RoundToDigits(-45.7) = -46
    RoundToDigits(-45.5) = -45 ' #5
    RoundToDigits(-45.3) = -45
    RoundToDigits(-45.37, 1) = -45.4
    RoundToDigits(-12.3456, 2) = -12.35
See also:
    RoundToDigitsVerify Subroutine
    RoundToPrecision Function
    Round Function (Visual Basic)
    Ceiling Function
    Floor Function
vNumber: The number that is rounded either up or down so that its precision is vDigits digits. 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.

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

Note: Function will return Null instead of generating an error if any of its calculations cause Overflow or other types of errors.

v1.5 Note: The Round function in Visual Basic 6.0 is the same as this function.

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