fn:round

Rounds a numeric value to a specified number of decimal places, with control over how the rounding takes place.

round($value as xs:numeric?, $precision as xs:integer?:=0, $mode as enum('floor', 'ceiling', 'toward-zero', 'away-from-zero', 'half-to-floor', 'half-to-ceiling', 'half-toward-zero', 'half-away-from-zero', 'half-to-even')?:='half-to-ceiling') ➔ xs:numeric?

Arguments

 

$value

xs:numeric?

The value to be rounded

 

$precision

xs:integer?

:= 0

The number of decimal places required

 

$mode

enum('floor', 'ceiling', 'toward-zero', 'away-from-zero', 'half-to-floor', 'half-to-ceiling', 'half-toward-zero', 'half-away-from-zero', 'half-to-even')?

:= 'half-to-ceiling'

The rounding mode

Result

xs:numeric?

Namespace

http://www.w3.org/2005/xpath-functions

Links to W3C specifications

XPath 3.1 Functions and Operators

XPath 4.0 Functions and Operators

Saxon availability

Available in XPath 2.0, XSLT 2.0, XQuery 1.0, and later versions. Available in all Saxon editions. Available for all platforms.

Notes on the Saxon implementation

The two-argument form of this function was introduced in XPath 3.0, and has been available since Saxon 9.3.

Saxon 12.6 fixed a long-standing bug (6537), whereby negative "midway" xs:decimal values were rounded away from zero rather than towards zero. For example round(-0.125e0, 2) returned -0.13 rather than -0.12.

XPath 4.0 introduces a 3-argument form of this function in which the rounding mode can be specified explicitly. This is implemented since Saxon 12.6; for details see the XPath 4.0 specification.