BUG: XSL FormatNumber Function Formats String Data Incorrectly with German Locale (293469)



The information in this article applies to:

  • Microsoft XML 2.0
  • Microsoft XML 2.5
  • Microsoft XML 2.6
  • Microsoft XML 3.0
  • Microsoft XML 3.0 SP1

This article was previously published under Q293469

SYMPTOMS

When you use the FormatNumber function with the "http://www.w3.org/TR/WD-xsl" namespace, and the computer's regional setting is set to German (Germany), the string data is formatted incorrectly.

For example, when you use the following Extensible Markup Language (XML) data
<amount currency='USD'>2.7</amount>
				
with the following
<xsl:template match='amount'>
   <xsl:eval>formatnumber(this.text, "###,##0.00")</xsl:eval>
</xsl:template>
				
the output is
27,00
				
The expected result is 2,70.

CAUSE

The period (.) decimal separator is ignored inside the string data on a computer whose regional setting is set to German (Germany). This causes the data to be formatted incorrectly.

NOTE: If you try to pass in "2,7" on a computer whose regional setting is set to English (United States), the comma (,) decimal separator is ignored.

RESOLUTION

This problem is discussed here for reference purposes only, because the Extensible Stylesheet Language (XSL) FormatNumber function has been superseded by the XSLT format-number function of the new "http://www.w3.org/1999/XSL/Transform" namespace.

There are two ways to work around this problem:
  • Always pass in a numeric value instead of string data to FormatNumber.
  • Use the new format-number function with xsl:decimal-format to set the decimal rules, as follows:
    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 
    <xsl:output method="html"/> <xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />
     <xsl:template match="/"> 
       <HTML><BODY> 
             <xsl:apply-templates select='root/amount' /> 
       </BODY></HTML> 
    </xsl:template> 
    <xsl:template match='amount'> 
    <xsl:value-of select="format-number(., '###.###,00', 'european')"/> </xsl:template>
    </xsl:stylesheet>
    					

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Paste the following code in an XML file, and save the file as Text.xml.
    <?xml version="1.0" ?>
    <?xml-stylesheet type='text/xsl' href='test.xsl' ?>
    <root>
    <amount currency='USD'>2.7</amount>
    </root>
    					
  2. Paste the following code in an Extensible Stylesheet Language (XSL) file, and save the file as Test.xsl.
    <?xml version="1.0" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match='/'>
       <html><body>
         <xsl:apply-templates select='root/amount' />
       </body></html>
    </xsl:template>
    <xsl:template match='amount'>
       <xsl:eval>formatnumber(this.text, "###,##0.00")</xsl:eval>
    </xsl:template>
    </xsl:stylesheet>
    					
  3. Change your computer locale to German (Germany). To do this, click Start, point to Settings, point to Control Panel, and click Regional Settings. On the General tab, under Your locale (location), select German (Germany).
  4. In Microsoft Internet Explorer, open Test.xml. You see the output as 27,00, which is incorrect.

Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug kbDSupport kbMSXMLnosweep KB293469