The round() function

Smartsite 7.4 - ...

The round() XPath 2.0 function rounds arg to a whole number.

XML CopyCode image Copy Code
numeric fn:round(arg)

Parameters:

  • arg: a node reference or literal.

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(pos)" />
   <xf:output value="fn:round(neg)" />
   <xf:output value="fn:round(2.5)" />
   <xf:output value="fn:round(2.49999)" />
   <xf:output value="fn:round(-2.5)" />
  </xf:group>
 </body>
</html>

The result will be:

11
-10
3
2
-2

Namespace

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