Share via


format-number Function (Compact 2013)

3/26/2014

Converts numbers into strings.

Syntax

string format-number(number, string, string?)

Parameters

  • number
    A number to be converted.
  • string
    String format pattern.
  • string
    [optional] Decimal format.

Return Value

Converts numbers into strings. The conversion is the result of formatting the number specified in the first argument (number), using the format specified in the second argument (string), and applying the rules defined in the decimal format named in the third optional argument (string). If the third argument, the decimal format name, is omitted, the default decimal format is used.

Remarks

The number argument specifies the input value. For example, the number 5351.

The first string argument specifies the format pattern. For the "format pattern" string, the following characters are supported "."; ","; "#","%","0", and the Unicode per-mille character (#x2030). The "#" character is used to describe integers. The "." and "," characters are used to describe the location and type of punctuation. The "0" character is used enforce digits before and after the "." character. When truncating digits to the right of the decimal points, the number is rounded. The number to the left of the decimal point is never truncated. If a second string argument is specified, representing a decimal format name, any character can be used in the format pattern string.

Both the input value and first string parameters must be present or an error will be thrown. If the first parameter cannot be coerced to a number, the function should return NaN. If the second parameter is not a valid pattern string, the number that is the first parameter is returned as is.

The second string argument, if present, represents the name of a decimal format, as specified using the <xsl:decimal-format> element. The decimal format name must be a qualified name. If you specify a decimal format name, there must be an <xsl:decimal-format> element in the style sheet with the same name.

Examples

The following function call returns "5,351".

format-number(5351,"#,###")

The following function call returns "5351.00".

format-number(5351, "#.00")

The following function call returns "53.5100".

format-number(53.51, "#.0000")

The following function call returns "0053.5100".

format-number(53.51, "0000.0000")

The following function call returns "0053.51".

format-number(53.51, "0000.####")

The following function call returns "53.6".

format-number(53.56, "0.0")

See Also

Reference

XSLT Functions