Name

[2.0] round-half-to-even()

Returns the integer closest to the argument, with the exception that any value that ends with .5 is rounded to the nearest even number.

Syntax

numeric? round-half-to-even(numeric?)
numeric? round-half-to-even(numeric?, $precision as xs:integer)

Inputs

A numeric value and an optional xs:integer specifying the number of digits of precision to be used in the calculation. The numeric value must be of type xs:float, xs:double, xs:decimal, or xs:integer. If it is not, the XSLT processor raises an error.

Output

The integer closest to the argument, with values ending in .5 rounded to the nearest even number. With that exception, round-half-to-even() works the same as round():

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

  • If the argument is NaN (not a number), then NaN is returned.

If the $precision argument is used, the XSLT processor returns the number closest to the value that is a multiple of 10 to the power of minus $precision. The value –2 rounds the number to the nearest 100, while the value 2 rounds the number to the nearest .01.

The output value has the same datatype as the input value. In other words, the function round-half-to-even(xs:integer) returns an xs:integer ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.