Loading TOC...

MarkLogic Server 11.0 Product Documentation
fn.roundHalfToEven

fn.roundHalfToEven(
   arg as Number?,
   [precision as Number]
) as Number?

Summary

The value returned is the nearest (that is, numerically closest) numeric to $arg that is a multiple of ten to the power of minus $precision. If two such values are equally near (e.g. if the fractional part in $arg is exactly .500...), returns the one whose least significant digit is even. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.

If no precision is specified, the result produces is the same as with $precision=0.

For arguments of type xs:float and xs:double, if the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned. If the argument is less than zero, but greater than or equal o -0.5, then negative zero is returned.

If $arg is of type xs:float or xs:double, rounding occurs on the value of the mantissa computed with exponent = 0.

For detailed type semantics, see Section 7.2.3 The fn:abs, fn:ceiling, fn:floor, fn:round, and fn:round-half-to-even functions[FS].

Parameters
arg A numeric value to round.
precision The precision to which to round the value.

Example

fn.roundHalfToEven(0.5)
=> 0

fn.roundHalfToEven(1.5) 
=> 2

fn.roundHalfToEven(2.5) 
=> 2

fn.roundHalfToEven(3.567812E+3, 2) 
=> 3567.81

fn.roundHalfToEven(4.7564E-3, 2) 
=> 0

fn.roundHalfToEven(35612.25, -2) 
=> 35600

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.