This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

# ROUND

Rounds a number.

## Synopsis

```ROUND(num[,precision])
```

### Arguments

 num An expression that resolves to a number or numeric string. precision Optional — An expression that resolves to an integer specifying the number of decimal digits to round to. If omitted, rounds to an integer.

## Description

The ROUND function returns a number rounded to the specified number of decimal digits. The number 5 is always rounded up. If precision is not specified, or is specified as 0, a negative number, or an non-numeric string, ROUND rounds num to an integer. If precision is specified, only those digits that were present in num can be returned. The precision argument specifies the maximum number of fractional digits to be returned; ROUND does not perform zero-padding of fractional digits.

For numerics, prior to rounding MVBasic performs all arithmetic operations and converts numbers to canonical form, removing leading and trailing zeroes, a trailing decimal point, and all signs except a single minus sign. For this reason, input trailing zeros are not returned, but decimal digits rounded to trailing zeros are returned.

## Examples

The following examples use the ROUND function to return a number rounded to an integer:

```PRINT ROUND(123.4);         ! Returns 123
PRINT ROUND(123.5);         ! Returns 124
PRINT ROUND(123.4,0);       ! Returns 123
PRINT ROUND(123.999,0);     ! Returns 124
PRINT ROUND(123,-1);        ! Returns 123```

The following examples use the ROUND function to return a number rounded to the specified number of decimal digits. Note that trailing zeros are only returned when they are the result of the rounding operation:

```PRINT ROUND(1.234,2);       ! Returns 1.23
PRINT ROUND(1.235,2);       ! Returns 1.24
PRINT ROUND(1.000,2);       ! Returns 1
PRINT ROUND(1.100,2);       ! Returns 1.1
PRINT ROUND(1.999,2);       ! Returns 2.00
PRINT ROUND(1.999,3);       ! Returns 1.999```