O'Reilly logo

XSLT by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required