xsl-list
[Top] [All Lists]

Re: [xsl] XPath 1.0: sum() and precision

2012-09-27 12:38:24
Does this help

http://flylib.com/books/en/2.765.1.41/1/

Recipe 3.2 XSLT cookbook

On Thu, Sep 27, 2012 at 6:32 PM, Florent Georges 
<lists(_at_)fgeorges(_dot_)org> 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?

  Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>