Re: number() floated?

Laurence Rowe <[email protected]>
Newsgroups gmane.comp.gnome.lib.xslt
Message-ID <CAOycyLQBnNda5BkiwVa_RVXyegt8PYM_vj7W-uwSs7WqV9YQOQ@mail.gmail.com>
On 16 December 2011 17:06, Konrad Korzeniowski <[email protected]> wrote:
> Hi there,
>
> I'm using 1.1.26-6 version of libxslt (Debian Lenny), and cannot find any
> explanation regarding described below behaviour.
>
> I got following simple xslt file:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
>     <xsl:template match="/">
>     <xsl:value-of select="number('8.95')"/>
>     </xsl:template>
> </xsl:stylesheet>
>
>
> running xsltproc with this xsl against any xml gives:
> 8.949999999999999
>
> Is this expected? Shouldn't this be 8.85?
>
> Thanks for any explanation.

Not all decimals may be exactly represented in binary floating point.
See: http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding

Laurence
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.