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

Re: XPath 1.0: sum() and precision

Subject: Re: XPath 1.0: sum() and precision
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 27 Sep 2012 19:08:37 +0100
Re:  XPath 1.0: sum() and precision
On 27 September 2012 18:32, Florent Georges <lists@xxxxxxxxxxxx> wrote:
>   Hi,
>
>   I have a question about sum() and precision in XPath 1.0.
> Let's say I have the following XML document:
>
>     <numbers>
>        <num>75</num>
>        <num>356.98</num>
>        <num>2052.51</num>
>     </numbers>
>
>   The expression "sum(/numbers/num)" returns something like
> 2484.490000000000000002 (and not 2484.49) because numbers are
> turned into xs:double instead of xs:decimal, and some precision
> is lost during floating-point computation.  In XPath 2.0, it's
> easy, I can just use instead "sum(/numbers/num/xs:decimal(.))",
> but this is not XPath 1.0.
>
>   What can I use in XPath 1.0 (so only XPath, and only 1.0) in
> order to get 2484.49?

I guess if you are stuck with xpath 1.0 it would have to be
substring... (or split on the ., then round() on the first 3 digits eg
the 490)


-- 
Andrew Welch
http://andrewjwelch.com

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.