The round-half-to-even() function

Smartsite 7.4 - ...

The round-half-to-even() XPath 2.0 function rounds a value to a specified number of decimal places, rounding to make the last digit even if two such values are equally near.

XML CopyCode image Copy Code
numeric fn:round-half-to-even(arg)
numeric fn:round-half-to-even(arg, integer precision)

Parameters:

  • arg: a node reference or literal.
  • integer precision (optional): the number of digits

Example

XML CopyCode image Copy Code
<html xmlns="http://www.w3.org/1999/xhtml" 
 xmlns:xf="http://www.w3.org/2002/xforms" 
 xmlns:fn="http://www.w3.org/2005/xpath-functions"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <head>
  <title>Example</title>
  <xf:model>
   <xf:instance>
    <data xmlns="">
     <pos>10.5</pos>
     <neg>-10.5</neg>
    </data>
   </xf:instance>
  </xf:model>
 </head>
 <body>
  <xf:group>
   <xf:output value="fn:round-half-to-even(pos)" />
   <xf:output value="fn:round-half-to-even(neg)" />
   <xf:output value="fn:round-half-to-even(0.5)" />
   <xf:output value="fn:round-half-to-even(1.5)" />
   <xf:output value="fn:round-half-to-even(2.5)" />
  </xf:group>
 </body>
</html>

The result will be:

10
-10
0
2
2

Namespace

This function is available within the XPath 2.0 namespace (http://www.w3.org/2005/xpath-functions).