Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project


   







XSLT FUNCTION:  format-number

string = format-number(number, format, decimal-format-qname)
 
The format-number function is used to convert a single number into a string. This number can be a real number or an integer, and can be positive or negative.
 
Note that the xsl:number element can be used to format a list of positive integers.
 
number
 
The mandatory number argument is the number that you want converted to a string. If the value is not of type number, it will automatically be converted to a number by the XPath number() function.
 
format
 
The mandatory format argument specifies the format pattern that dictates the appearance of the formatted number. Some of the permitted symbols in the format pattern are:
 
Symbol Purpose Example
# signifies a digit [0-9] ###
. decimal point ###.##
, group separator ###,###.##
0 specifies leading and following zeros 00000.00000
% inserts following percent sign ##%
; pattern separator ##.00;##.00

 
decimal-format-qname
 
The optional decimal-format-name argument is a qname that matches the qname value of the name attribute of the xsl:decimal-format element. The xsl:decimal-format element must be present to use this argument. If this argument is omitted, the default decimal format is used. However, you can create your own default decimal format by using the xsl:decimal-format element without a name attribute.
 
We display several numeric format variations.
 
Code for xslt_example_formatnumber.xsl:
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:decimal-format name="staff" digit="D" />
<xsl:template match="/">
<html>
<body>
<xsl:value-of select='format-number(123456789, "#.000000000")' />
<br />
<xsl:value-of select='format-number(123456789, "#.0")' />
<br />
<xsl:value-of select='format-number(0.123456789, "##%")' />
<br />
<xsl:value-of select='format-number(123456789, "################")' />
<br />
<xsl:value-of select='format-number(123456789, "D.0", "staff")' />
<br />
<xsl:value-of select='format-number(123456789, "$DDD,DDD,DDD.DD", "staff")' />
<br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

 
Output:
 
Click to view output in separate window - requires Internet Explorer

 
 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information