Subject: Re: [xsl] sum() function giving strange result From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 14 Dec 2004 10:33:10 GMT |
> 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 ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] sum() function giving strange, Arun Sinha | Thread | RE: [xsl] sum() function giving str, Jarno.Elovirta |
RE: [xsl] Different (body) layout o, Arun Sinha | Date | [xsl] Discard a "." in an element v, Beatriz Langiano |
Month |