Microsoft KB Archive/293469

= BUG: XSL FormatNumber Function Formats String Data Incorrectly with German Locale =

Article ID: 293469

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1

-



This article was previously published under Q293469



SYMPTOMS
When you use the FormatNumber function with the &quot;http://www.w3.org/TR/WD-xsl&quot; 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 2.7 with the following  formatnumber(this.text, &quot;###,##0.00&quot;)  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 &quot;2,7&quot; 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 &quot;http://www.w3.org/1999/XSL/Transform&quot; 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:    <xsl:decimal-format name=&quot;european&quot; decimal-separator=',' grouping-separator='.' /> <xsl:template match=&quot;/&quot;> <HTML><BODY> <xsl:apply-templates select='root/amount' /> </BODY></HTML> </xsl:template> <xsl:template match='amount'> <xsl:value-of select=&quot;format-number(., '###.###,00', 'european')&quot;/> </xsl:template> </xsl:stylesheet> </li></ul>

<div class="status_section">

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

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol>  Paste the following code in an XML file, and save the file as Text.xml. <?xml version=&quot;1.0&quot; ?> <?xml-stylesheet type='text/xsl' href='test.xsl' ?> <amount currency='USD'>2.7 </li>  Paste the following code in an Extensible Stylesheet Language (XSL) file, and save the file as Test.xsl. <?xml version=&quot;1.0&quot; ?> <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/TR/WD-xsl&quot;> <xsl:template match='/'> <xsl:apply-templates select='root/amount' /> </xsl:template> <xsl:template match='amount'> formatnumber(this.text, &quot;###,##0.00&quot;)</xsl:eval> </xsl:template> </xsl:stylesheet> </li> 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).</li> In Microsoft Internet Explorer, open Test.xml. You see the output as 27,00, which is incorrect.</li></ol>

Keywords: kbbug kbfix kbmsxmlnosweep KB293469

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.