xsl-list
[Top] [All Lists]

[xsl] XPath / XSLT 2.1 - Rounding algorithms

2008-11-13 16:57:42
A couple of years ago, I ran into a need to call extension functions
to round numbers in the "traditional" way: to round half up for results of
.5 (or more).  I found that it was only possible with XSLT to round to the even
number.

I am aware that rounding to the nearest even number is the theoretically correct
thing to do, this was pointed out at the time.

However, this is not the default rounding method in most commonly available 
office software, and lots of other types of software.

Being able to reproduce results from existing systems might help in the
growth of XPath and XSLT in replacing non-standard languages in the
workplace.  In any case, for some applications, it could be important to have
access to the IEEE standard algorithms without having to resort to 
(complicated) extension functions / jump through hoops.

http://en.wikipedia.org/wiki/IEEE_754#Rounding_algorithms

Specifically, round-half-up(decimal_num,num_digits), where 'up' means towards
positive or negative infinity, is what I'm looking for.

Peter Rushforth
Technology Advisor / Conseiller technique
GeoConnections / GéoConnexions
650-615 Booth St. / rue Booth
Ottawa ON K1A 0E9
E-mail / Courriel: Peter.Rushforth @ NRCan.gc.ca 
Phone / Télephone: (613) 943-0784 
Fax / telecopier:  (613) 947-2410

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