[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calculating a sum of rounded numbers

Subject: Calculating a sum of rounded numbers
From: "Nik Krimm" <Nik.Krimm@xxxxxxxxxxxxxxx>
Date: Thu, 9 May 2002 15:45:22 -0500
the sum of a number
I am trying the following output from the XML below:

[output]
.21 
.09
.2 
sum: .5

[xml]
<values>
<value>.2123</value>
<value>.0923</value>
<value>.2012</value>
</values>


<xsl:for-each select="value">
	<xsl:value-of select="format-number((.),'.##')" /><br />
</xsl:for-each>
sum: <xsl:value-of select="format-number(sum(//value),'.##)" />

Instead I'm getting the output

[output]
.21 
.09
.2 
sum: .51

i.e. a rounding error because the numbers are sumed first and then rounded, rather than rounded first and then summed.


I tried
<xsl:value-of select="format-number(sum(format-number(//measure),'##')" />

But get an error: 
Argument 1 must return a node-set.
format-number(-->sum(format-number(//measure),'##')<--)

Can anyone suggest a better way to approach this problem that is native xsl (i/e/ without extensions)?


TIA

nik




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.