[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] XPath 1.0: sum() and precision

Subject: [xsl] XPath 1.0: sum() and precision
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Thu, 27 Sep 2012 18:32:55 +0100 (BST)


  I have a question about sum() and precision in XPath 1.0.
Let's say I
have the following XML document:


  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?


Florent Georges

Current Thread