Stylus Studio XML Editor

Table of contents

Appendices

4.4 Number Functions

Number Functions

number number(object?)

The number function converts its argument to a number as follows:

  • a string that consists of optional whitespace followed by an optional minus sign followed by a [Number] followed by whitespace is converted to the IEEE 754 number that is nearest (according to the IEEE 754 round-to-nearest rule) to the mathematical value represented by the string; any other string is converted to NaN

  • boolean true is converted to 1; boolean false is converted to 0

  • a node-set is first converted to a string as if by a call to the string function and then converted in the same way as a string argument

  • an object of a type other than the four basic types is converted to a number in a way that is dependent on that type

If the argument is omitted, it defaults to a node-set with the context node as its only member.

NOTE: 

The number function should not be used for conversion of numeric data occurring in an element in an XML document unless the element is of a type that represents numeric data in a language-neutral format (which would typically be transformed into a language-specific format for presentation to a user). In addition, the number function cannot be used unless the language-neutral format used by the element is consistent with the XPath syntax for a [Number] .

number sum(node-set)

The sum function returns the sum, for each node in the argument node-set, of the result of converting the [string-value] s of the node to a number.

number floor(number)

The floor function returns the largest (closest to positive infinity) number that is not greater than the argument and that is an integer.

number ceiling(number)

The ceiling function returns the smallest (closest to negative infinity) number that is not less than the argument and that is an integer.

number round(number)

The round function returns the number that is closest to the argument and that is an integer. If there are two such numbers, then the one that is closest to positive infinity is returned. If the argument is NaN, then NaN is returned. If the argument is positive infinity, then positive infinity is returned. If the argument is negative infinity, then negative infinity is returned. 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 to -0.5, then negative zero is returned.

NOTE: 

For these last two cases, the result of calling the round function is not the same as the result of adding 0.5 and then calling the floor function.