xsl-list
[Top] [All Lists]

Re: sum() function giving strange result

2004-12-14 03:33:10

I am worried about the output 151.64999999999998. Why is it outputting this 
value?

Most computers these days use binary arithmetic. This means that they
can not store a number such as 10.11 exactly (or rather, they could
store it exactly, but they don't) so as your input is not stored exactly
you shouldn't expect exact results (from any computer arithmetic).
You can use the format-number function to round the result to 2dp.

<xsl:variable name="SubTotals">
  <xsl:for-each  select="/documents/value">
    <value><xsl:value-of select="." /></value>
  </xsl:for-each>
</xsl:variable>

don't do that, so this:

<xsl:variable name="SubTotals" select="/documents/value"/>
it's far more efficient and means that you would not need to use teh
node-set() extension to do the sum.


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--