Name

round() Function — Returns the integer closest to the argument.

Synopsis

number round(
               number
               )

Description

If two numbers are equally close to the argument (1 and 2 are equally close to 1.5), the number closest to positive infinity is returned. Various argument values are handled as follows:

  • If the argument is NaN (not a number), the round() function returns NaN.

  • If the argument is positive infinity, then positive infinity is returned.

  • If the argument is negative infinity, then negative infinity is returned.

  • If the argument is positive zero, then positive zero is returned.

  • If the argument is negative zero, then negative zero is returned.

  • If the argument is between zero and -0.5, then negative zero is returned.

Inputs

A number. If the argument is not a number, it is converted to a number as if it were passed to the number() function.

Output

The integer that is closest to the argument. Special cases are handled as described in this section.

Defined in

XPath section 4.4, Number Functions.

Example

The following stylesheet shows the results of invoking the round() function against a variety of values. We’ll use this XML document as input:

<?xml version="1.0"?> <report> <title>Miles Flown in 2001</title> <month sequence="01"> <miles-flown>12379</miles-flown> <miles-earned>35215</miles-earned> </month> <month sequence="02"> <miles-flown>32857</miles-flown> <miles-earned>92731</miles-earned> </month> <month sequence="03"> <miles-flown>19920</miles-flown> <miles-earned>76725</miles-earned> </month> ...

Get XSLT now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.