XSLT format-number() Function

Definition and Usage

The format-number() function is used to convert numbers to strings.

Syntax

string format-number(number,format,[decimalformat])

Parameter

Parameter Description
number Required. Specifies the number to be formatted.
format

Required. Specifies the formatting pattern. These are the characters used in the formatting pattern:

  • # (indicates numbers. For example: ####)
  • 0 (indicates zeros before and after the dot. For example: 0000.00)
  • . (position of the decimal point. For example: ###.##)
  • , (thousand's separator. For example: ###,###.##)
  • % (display numbers as percentages. For example: ##%)
  • ; (pattern separator. The first pattern is used for positive numbers, the second pattern is used for negative numbers.)
decimalformat Optional. Decimal format name.

Example

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:template match="/">
<html>
<body>
<xsl:value-of select='format-number(500100, "#.00")' />

<xsl:value-of select='format-number(500100, "#.0")' />
<xsl:value-of select='format-number(500100, "###,###.00")' />
<xsl:value-of select='format-number(0.23456, "##%")' />
<br /> </body> </html> </xsl:template> </xsl:stylesheet>

View XSL File,View Results.