Number formatting

Format-number function

Using the format-number() function, numeric values can be formatted as required. The first parameter is the string containing the number to be formatted. The second parameter is a template to be used to format this number.

In the following example, the template ensures that the price has two digits after the decimal point:

   <price val="3.5"/>


Price: <value-of select="format-number(@val, '0.00')"/>.


   3.50

The template may contain a number of significant symbols. As indicated above, '0' indicates that a digit must appear at this position, and the '.' symbol indicates the position of the decimal point. In addition, the '#' symbol indicates the position of possibly absent digits, and is used in conjunction with commas, which specifies where grouping separators should appear. When used after a decimal point, the '#' symbol is used to restrict the number of digits output. For example, the template '###,###,#00.0#' would create '132,456,789.12' from the value '123456789.1234'. The semicolon character separates two templates, the second being for negative numbers. The '%' symbol indicates a percentage value (fractions such as '0.2' are converted to '%20'). In the same way, the '?' symbol represents 'per mille' (per thousand). Finally, the international currency symbol stands in for an appropriate local currency symbol, such as '$'.

Format element

The formatting template described above makes some assumptions that are not always relevant. The full point and comma characters are not universally used in numbers, or their roles may be different. The Decimal Format element may be used to specify alternative symbols to be used in both the formatting template and the output. For example, in France the full point and comma character roles are reversed. The Decimal Separator and Grouping Separator attributes specify the character to use for each role:

<decimal-format decimal-separator=","
                grouping-separator="." ... >

This element has a Name attribute, and its value is referenced from the function that wishes to use these settings:

<decimal-format name="France" ... />

<value-of select="format-number(@val, '0,00', France)" />


3,50

In some languages, '-' is not used as a minus sign, '%' is not used for percentages, and '0' is not used for zero digits. The Minus Sign, Percent, Per Mille and Zero Digit attributes are used to override these defaults:

<decimal-format ... minus-sign="M" percent="P"
                    per-mille="?" zero-digit="Z" />

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.181.52