Converts a number into a string and formats it according to the specified options.
Built-in, C++, C#, Java, XSLT 1.0, XSLT 2.0, XSLT 3.0.
Mandatory argument. Supplies the number to be formatted.
Mandatory argument. Supplies a format string that identifies the way in which the number is to be formatted. See "Remarks" below.
Optional argument. Supplies the character to be used as the decimal point character. The default value is the full stop ( . ) character.
Optional argument. Supplies the character used to separate groups of numbers. The default value is the comma ( , ) character.
|Note:||If the function’s output (result) is connected to an item of type other than string, the formatting may be lost as the value is cast to the target type. To disable this automatic cast, clear the Cast target values to target types check box in the Component Settings of the target component.|
The format argument takes the following form:
format := subformat (;subformat)?
subformat := (prefix)? integer (.fraction)? (suffix)?
prefix := any characters except special characters
suffix := any characters except special characters
integer := (#)* (0)* ( allowing ',' to appear)
fraction := (0)* (#)* (allowing ',' to appear)
The first subformat is used for formatting positive numbers, and the second subformat for negative numbers. If only one subformat is specified, then the same subformat will be used for negative numbers, but with a minus sign added before the prefix.
A digit will always appear at this point in the result
A digit will appear at this point in the result string unless it is a redundant leading or trailing zero
Separates the integer and the fraction part of the number.
Separates groups of digits.
Multiplies the number by 100 and shows it as a percentage.
Multiplies the number by 1000 and shows it as per-mille.
The table below illustrates examples of format strings and their result.
|Note:||The rounding method used by the format-number function is "half up", which means that the value gets rounded up if the fraction is greater than or equal to 0.5. The value gets rounded down if the fraction is less than 0.5. This method of rounding applies only to generated program code and the built-in execution engine. In XSLT 1.0, the rounding mode is undefined. In XSLT 2.0, the rounding mode is "round-half-to-even".|
The mapping illustrated below reads data from source XML and writes it to a target XML. There are multiple SinglePrice elements in the source that contain the following decimal values: 25, 2.30, 34, 57.50. The mapping has two goals:
1.Pad all values with zeros to the left so that the significant part takes 5 digits exactly
2.Pad all values with zeros to the right so that the decimal part takes 2 digits exactly
To achieve this, the format string 00000.00 was supplied as argument to the format-number function.
Consequently, the values in the target have become:
You can find the mapping design file at the following path: <Documents>\Altova\MapForce2022\MapForceExamples\PreserveFormatting.mfd.