Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Usage
The
format-number()
function to output numeric information. It is designed primarily to provide localization of the format for display to human readers, but it can also be useful when you need to produce an output data file using, for example, a fixed number of leading zeroes. It is typically used for numbers in the source data or computed from the source data, whereas the
Each
Examples
The tables in the following examples illustrate some of the effects achievable using the
Example 1: Comma as a Decimal Separator
This decimal format is used in many Western European countries; it uses a comma as a decimal point and a period (full stop) as a thousands separator, the reverse of the custom in Britain and North America.
The left-hand column shows the number as it would be written in XSLT. The middle column shows the picture string supplied as the second argument to the
format-number()
function. The right-hand column shows the string value returned by the
format-number()
function.
The patterns used in this example use the following symbols:
Number | Picture String | Result |
1234.5 | #.##0,00 | 1.234,50 |
123.456 | #.##0,00 | 123,46 |
1000000 | #.##0,00 | 1.000.000,00 |
−59 | #.##0,00 | 59,00 |
1e0 div 0 | #.##0,00 | Infinity |
1234 | ###0,0### | 1234,0 |
1234.5 | ###0,0### | 1234,5 |
.00035 | ###0,0### | 0,0004 |
0.25 | #00% | 25% |
0.736 | #00% | 74% |
1 | #00% | 100% |
42 | #00% | 4200% |
−3.12 | #,00;(#,00) | (3,12) |
−3.12 | #,00;#,00CR | 3,12CR |