xsl-list
[Top] [All Lists]

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

2012-09-27 18:16:28

On 27/09/2012 23:09, Florent Georges wrote:
Andrew Welch wrote:

   Hi,

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)
   Thanks Andrew.  That's what I thought too, but I wanted to avoid
string functions for that purpose.  What I've done in the meantime is
replacing sum(...) by:

     round(sum(...) * 100) div 100

that is, "moving the dot right", rounding as an integer, then "moving
the dot left" again.



But can't the "div 100" itself have a rounding error that means you don't get an exact answer?

In pure XPath 1.0, without format-number(), I suspect string manipulation is the only reliable way.

Michael Kay
Saxonica

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