home contribute faq download

FunctX XSLT Functions

fn:round-half-to-even

Rounds a numeric value, rounding even halfs to the nearest even number

Google
Webxsltfunctions.com

Description

The fn:round-half-to-even 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 Type

NameTypeDescription
$arg numeric? the number to round
$precision xs:integer the precision to round it to
return value numeric?

Examples

XPath ExampleResults
round-half-to-even(5.5)
6
round-half-to-even(6.5)
6
round-half-to-even(9372.253, 2)
9372.25
round-half-to-even(9372.253, 0)
9372
round-half-to-even(9372.253, -3)
9000

See Also

fn:roundRounds a numeric value
fn:ceilingRounds up to the next highest integer
fn:floorRounds down to the next lowest integer

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XSLT Services

Recommended Reading:

XQuery