Re: [xslt] floating point conversion



On 10/09/10 18:26, Phil Shafer wrote:
I'm looking into an issue with floating point rounding, and
have hit an issue with number conversion.

The crux is that number("100.15") is not equal to 100.15.

That's how floating point numbers work.

% cat /tmp/test.xslt
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
   <xsl:output method="xml" indent="yes"/>
   <xsl:template match="/">
     <op-script-results>
       <output>
         <xsl:value-of select="format-number('100.15', '####.################')"/>
       </output>
       <output>
         <xsl:value-of select="format-number(100.15, '####.################')"/>
       </output>
       <output>
         <xsl:value-of select="format-number(number('100.15') , '####.################')"/>
       </output>
     </op-script-results>
   </xsl:template>
</xsl:stylesheet>
% xsltproc /tmp/test.xslt /tmp/test.xml
<?xml version="1.0"?>
<op-script-results>
   <output>100.1500000000000057</output>
   <output>100.1499999999999915</output>
   <output>100.1500000000000057</output>
</op-script-results>

% xsltproc --version
Using libxml 20707, libxslt 10126 and libexslt 815
xsltproc was compiled against libxml 20707, libxslt 10126 and libexslt 815
libxslt 10126 was compiled against libxml 20707
libexslt 815 was compiled against libxml 20707

Can anyone point me in the right direction for tracking this down?

That the second number is different seems to be a bug in libxml2. The implementations of xmlXPathStringEvalNumber and xmlXPathCompNumber are slightly different AFAICS.

Nick


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]