XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Rounding functions for numeric types
A number of numeric type; the next higher integer of the number passed on as argument – after rounding up, but without changing the data type. (In XPath 1.0 the return value is of number type.)
Optional. The number to be rounded. In XPath 2.0 this number has to correspond to one of the numeric data types or to one of the types derived from it. (However, in XPath 1.0 an implicit type conversion is made for ceiling() according to the number() function.)
Purpose of use:
The fn:ceiling() function rounds a number passed on to it belonging to one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer or to one of the types derived from these in positive direction up to the next higher integer. The data type of the number is preserved, provided that it is a base type (there is no conversion into the xs:integer type).
If the input type is a type derived from one of the numeric base types (derived type), the rounding result gets the appropriate base type. If the input value has the xs:untypedAtomic type, this type is cast to xs:double by means of type promotion. The return value also gets this type. In case the input number is already an integer, the value remains unchanged. A negative input number is rounded up to the next higher (which means the next lowest from the absolute value!) negative integer.
If the empty sequence is passed on to the function, it also returns the empty sequence. If (input type xs:double or xs:float) the input value is NaN, NaN is also returned.
Exceptions: Input values of type xs:double or xs:float being +0 (positive zero) or -0 (negative zero) are returned unchanged.
Behaviour in XPath 1.0:
In XPath 1.0, the call of ceiling() with a string argument being successfully convertible to numerical returns a number or otherwise NaN:
ceiling('2.2') results in 3.
ceiling('a_string') results in NaN.
If an empty string is passed on under XPath 1.0, the result is NaN. If (halfway comparable) in XPath 2.0 the value passed on is an empty sequence, the result, however, is an empty result sequence.
|fn:ceiling(16 div 3)||6|
|fn:ceiling(1 div 0)||INFINITY|
|fn:ceiling(-1 div 0)||-INFINITY|
Table: examples for the fn:ceiling() function
fn:ceiling($arg as numeric?) as numeric?
|<< back||next >>|
Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany