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

RE: msxml sum() and precision problem

Subject: RE: msxml sum() and precision problem
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 19 Sep 2002 15:42:25 +0100
sum in xsl
XPath 1.0 uses floating-point binary arithmetic, not decimal arithmetic,
so there will be rounding errors when results are converted to decimal.
Use format-number() to display the results to the required precision.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Jonas Nordström
> Sent: 19 September 2002 13:03
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  msxml sum() and precision problem
> 
> 
> Something strange is going on. I strolled through the 
> archives but couldn't find something similar. Consider the following:
> 
> test.xml:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="test.xsl"?>
> 
> <jonas>
> 	<name amount="349.03"/>
> 	<name amount="895.01"/>
> 	<name amount="841.03"/>
> </jonas>
> 
> 
> test.xsl:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> <xsl:stylesheet  version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
> <xsl:output method="html" version="4.0" encoding="ISO-8859-1"/>
> 
> <xsl:template match="/">
> 
> <html>
>   <meta http-equiv="Content-Type" content="text/html; 
> charset=ISO-8859-1" /> <head> </head> <body> 
> <xsl:apply-templates select="/jonas/name" /> <br/>
> Sum: <xsl:value-of select="sum(/jonas/name/@amount)" />
> </body>
> </html>
> </xsl:template>
> 
> <xsl:template match="/jonas/name">
>    <xsl:value-of select="position()"/>: <xsl:value-of 
> select="@amount" /><br/> </xsl:template>
> 
> </xsl:stylesheet>
> 
> and the stunning browser-result:
> 1: 349.03
> 2: 895.01
> 3: 841.03
> 
> Sum: 2085.0699999999997 
> 
> Is there a known precision bug for sum in MSXML (I'm running 
> MSXML3 i think).
> 
>  - Jonas Nordstrom -
> Sigma Exallon AB
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.