Round - VBScript


Overview

Round is a VB Script command used for rounding numeric values to specified decimal places or the nearest integer. It is commonly used to represent numerical data in a more concise and meaningful way.

Syntax

Round(number, [numDecimalPlaces])

| Parameter | Description |
|—|—|
| number | The numeric value to be rounded. |
| numDecimalPlaces | The number of decimal places to round to. Default: 0. |

Options/Flags

None

Examples

Example 1: Round a decimal to the nearest integer

Dim result = Round(12.5)

Output:

12

Example 2: Round a decimal to two decimal places

Dim result = Round(12.3456, 2)

Output:

12.35

Common Issues

  • Ensure that the input value is a valid numeric type. Invalid input can result in errors.
  • Be cautious of rounding errors when using high precision values.

Integration

Round can be used in conjunction with other VB Script commands to perform advanced calculations. For example:

Dim roundedValue = Round(Sum(arrayValues) / Count(arrayValues), 2)