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 ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.