Description
The fn:roundhalftoeven function rounds a numeric value, rounding even halfs to the nearest even number. This type of rounding is used in financial applications so that the sum of a column of rounded numbers comes closer to the sum of the same unrounded numbers.
The returned value is rounded to the number of decimal places indicated by $precision . For example, if the precision specified is 2, the function rounds 594.3271 to 594.33. If the precision is 0, the number is rounded to an integer. Specifying a negative precision results in the number being rounded to the left of the decimal point. For example, if $precision is 2, the function rounds 594.3271 to 600. If $precision is omitted, it defaults to 0.
If the argument is exactly half way between two values, it is rounded to whichever adjacent value is even.
The result type depends the numeric type of the argument. If $arg is untyped, it is cast to xs:double .
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName  Type  Description 
$arg 
numeric? 
the number to round 
$precision 
xs:integer 
the precision to round it to 
return value 
numeric? 
ExamplesXPath Example  Results 

roundhalftoeven(5.5) 
6 
roundhalftoeven(6.5) 
6 
roundhalftoeven(9372.253, 2) 
9372.25 
roundhalftoeven(9372.253, 0) 
9372 
roundhalftoeven(9372.253, 3) 
9000 
See AlsoHistory 
Recommended Reading:
