Table of Contents

Search

  1. Preface
  2. Taskflows and linear taskflows
  3. Taskflows
  4. Linear taskflows

Taskflows

Taskflows

round (Numbers)

round (Numbers)

Rounds numbers to a specified number of digits or decimal places. You can also use round to round dates.
The Round function behaves as follows:
  • Returns the number without the fractional part that is closest to the argument.
  • If there are two numbers that are close to the argument, then the number that is closest to the positive infinity is returned.
  • If the data type of the argument is one of the four numeric data types, xs:float, xs:double, xs:decimal, or xs:integer, then the data type of the result is the same as the data type of the argument.
  • If the data type of the argument is a data type derived from one of the numeric data types, then the result is an instance of the base numeric data type.

Syntax

fn:round(arg)
The following table describes the argument for this command:
Argument
Required/
Optional
Description
arg
Required
Must be a numeric data type. You can enter any valid transformation expression. Use operators to perform arithmetic before you round the values.
To pass a NULL value, you must specify an empty sequence in the following format:
()
The function rounds to the nearest integer, truncating the decimal portion of the number. For example, round(12.99) returns 13 and round(15.20) returns 15.

Return Value

Numeric value.
If one of the arguments is NULL, round returns NULL.
Example
The following expression returns the rounded values in the Price column.
fn:round(PRICE)
The following table lists some sample values and return values:
PRICE
RETURN VALUE
12.99
13.0
-15.99
-16.0
-18.99
-19.0
56.95
57.0
NULL
NULL
If you want to be more specific with the precision and round the number to the nearest integer or truncate the decimal portion, it is recommended to use round-half-to-even function.
fn:round-half-to-even(arg, precision)
If you enter a positive precision, the function rounds to this number of decimal places. For example, round(12.99, 1) returns 13.0 and round(15.44, 1) returns 15.4.
If you enter a negative precision, the function rounds this number of digits to the left of the decimal point, returning an integer. For example, round(12.99, -1) returns 10 and rounds(15.99, -1) returns 20.
The value returned is the nearest, that is, numerically closest value to the argument that is a multiple of ten to the power of minus precision. If two such values are equally near, that is, if the fractional part in the argument is exactly .500..., the function returns the one whose least significant digit is even.

Example

The following expression returns the values in the Price column rounded to three decimal places.
fn:round-half-to-even(PRICE, 3)
The following table lists some sample values and return values:
PRICE
RETURN VALUE
12.9936
12.994
15.9949
15.995
-18.8678
-18.868
56.9561
56.956
NULL
NULL
You can round digits to the left of the decimal point by passing a negative integer in the precision argument:
fn:round-half-to-even(PRICE, -2)
The following table lists some sample values and return values:
PRICE
RETURN VALUE
13242.99
13200.0
1435.99
1400.0
-108.95
-100.0
NULL
NULL
If you pass zero in the precision argument, the function rounds to the nearest integer:
fn:round-half-to-even(PRICE, 0)
The following table lists some sample values and return values:
PRICE
RETURN VALUE
12.99
13.0
-15.99
-16.0
-18.99
-19.0
56.95
57.0
NULL
NULL

0 COMMENTS

We’d like to hear from you!