Round Function
Returns a number rounded to a specified number of decimal places.
Syntax
Round(expression[, numdecimalplaces])
Arguments:
- Expression: Required. Numeric expression being rounded.
- Numdecimalplaces: Optional. Number indicating how many places to the right of the decimal are included in the rounding. If omitted, integers are returned by the Round function.
Remarks
The Round
function performs round to even, which is different from
round to larger. The return value is the number closest to the value of expression,
with the appropriate number of decimal places. If expression is exactly halfway
between two possible rounded values, the function returns the possible rounded value
whose rightmost digit is an even number. (In a round to larger function, a number
that is halfway between two possible rounded values is always rounded to the larger
number.)
Note:
Round to even is a statistically more accurate rounding algorithm than round to larger.
The following example uses the round
function to round a number to
two decimal places:
Dim MyVar, pi
pi = 3.14159
MyVar = Round(pi, 2)
' Output: 3.14.
This example demonstrates how rounding to even works:
Dim var1, var2, var3, var4, var5
var1 = Round(1.5)
' Output: 2
var2 = Round(2.5)
' Output: 2
var3 = Round(3.5)
' Output: 4
var4 = Round(0.985, 2)
' Output: 0.98
var5 = Round(0.995, 2)
' Output: 1
Dim MyVar
MyVar = Round(5.678)
'Output: 6.
Dim MyVar
MyVar = Round(-2.675, 2)
' Output: -2.68.