O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

format-number()

Takes a number and formats it as a string.

Syntax

[1.0] string format-number($value as number, $picture as string, 
                           $formatName as string?)
[2.0] xs:string format-number($value as numeric, $picture as xs:string, 
                              $formatName as xs:string?)

Inputs

The number to be formatted and the format pattern string are required. The third argument is the optional name of a decimal format; if the third argument is not supplied, the default decimal format is used.

[2.0] The numeric argument must be one of the four numeric types (xs:float, xs:decimal, xs:double, or xs:integer). If it is not a numeric type or cannot be converted to one, the XSLT processor raises an error. The XSLT processor also raises an error if the named decimal format does not exist.

Output

The number, formatted according to the rules supplied by the other arguments. The special characters used in the second argument are:

#

Represents a digit. Trailing or leading zeroes are not displayed. Formatting the number 4.0 with the string #.## returns the string 4.

0

Represents a digit. Unlike the # character, the 0 always displays a zero. Formatting the number 4.1 with the string #.00 returns the string 4.10.

.

Represents the decimal point.

Represents the minus sign.

,

Is the grouping separator.

;

Separates the positive-number pattern from the negative-number pattern.

%

Indicates that a number should be displayed as a percentage. The value will be multiplied by 100, then displayed as a percentage. Formatting the number .76 with the string ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required