Name

Round Function

Syntax

Round(expression[, numdecimalplaces])
expression

Use: Required

Data Subtype: Numeric

Any numeric expression.

numdecimalplaces

Use: Optional

Data Subtype: Long

The number of places to include after the decimal point.

Return Value

The same data subtype as expression.

Description

Rounds a given number to a specified number of decimal places.

Rules at a Glance

  • numdecimalplaces can be any whole number between and 16.

  • Round follows standard rules for rounding:

    • If the digit in the position to the right of numdecimalplaces is greater than 5, the digit in the numdecimalplaces position is incremented by one.

    • If the digit in the position to the right of numdecimalplaced is less than 5, the digits to the right of numdecimalplaces are dropped.

    • If the digit in the position to the right of numdecimalplaces is 5 and the digit in the numdecimalplaces position is odd, the digit in the numdecimalplaces position is incremented by one.

    • If the digit in the position to the right of numdecimalplaces is 5 and the digit in the numdecimalplaces position is even, the digits to the right of numdecimalplaces are dropped.

Programming Tips & Gotchas

  • If expression is a string representation of a numeric value, Round converts it to a numeric value before rounding. However, if expression isn’t a string representation of a number, Round generates runtime error 13, “Type mismatch.” The IsNumeric function insures that expression is a proper numeric representation before calling Round.

  • If expression contains ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.