format-number

Format a number

Description

The fn:format-number function formats $value as a string using the picture string specified by $picture and $decimal-format-name or the default decimal-format, if there is no $decimal-format-name argument. The syntax of the picture string is described in section 16.4.2 of the XSLT 2.0 recommendation. Note: this is an XSLT-only function; it is not available in XQuery or XPath.

Parameters

Description

value:numeric()

the number to format

picture:string()

the picture string, such as #,##0.00

decimal-format-name:string()

the name of an xsl:decimal-format; optional

Examples

XPath

Results

format-number(1234.5, '#,##0.00')

1,234.50

format-number(0.25, '0%')

25%

format-number(12, '000')

012

format-number(3.14159, '0.##')

3.14

In a generator

Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-format-number.

[e] example-format-number
    [e] start
        [e] match
            [v] /
        [e] body
            [e] write-pattern
                [v] examples
    [e] patterns
        [e] examples
            [v] E01: {{ format-number(1234.5, '#,##0.00') }}
            [v] E02: {{ format-number(0.25, '0%') }}
            [v] E03: {{ format-number(12, '000') }}
            [v] E04: {{ format-number(3.14159, '0.##') }}

See Also