Subject: Re: Xalan Rounding
From: Jeff Kenton <jkenton@xxxxxxxxxxxxx>
Date: Fri, 10 May 2002 15:08:11 -0400 (EDT)
|
On Fri, 10 May 2002, Nik Krimm wrote:
..Another rounding question [sorry]:
..
..With the format-number function, if the the digit to be rounded off has a value of exactly .5, xalan rounds down. Regular round() produced the expected result (rounding up); however I'd prefer to use the format-number function because this template may output various precision decimals (0 - n decimal places). Sticking with format-number() would allow me to pass this information is as a $format variable.
..
..Any suggestions on how to handle this?
I just tried your test with both Xalan and Saxon. With a value of 106.5,
I saw rounding down to 106 with both. With a value of 107.5, it rounded
up to 108.
I suspect that what you are seeing is IEEE-754 round to nearest mode,
which says that ties are broken by rounding to an even value (don't ask
why unless you *REALLY* care why it's specified that way).
If this is the cause of what you're seeing (and I'm seeing), this is not
what XSLT requires.
..
..[xml]
..<values>
..<value>106.5</value>
..</values>
..
..
..<xsl:template name="average-values">
..<xsl:param name="format">###</xsl:param>
..<xsl:value-of select="format-number(//value ,'##')" />
..</xsl:template>
..
..[xalan output]
..106
..
..[desired output]
..107
..
..TIA
..
.. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
..
--
Jeff Kenton
DataPower Technology, Inc.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- Xalan Rounding
- Nik Krimm - Fri, 10 May 2002 14:32:22 -0400 (EDT)
- Jeff Kenton - Fri, 10 May 2002 15:16:22 -0400 (EDT) <=
- Stuart Celarier - Fri, 10 May 2002 15:24:42 -0400 (EDT)
- <Possible follow-ups>
- Nik Krimm - Fri, 10 May 2002 16:06:33 -0400 (EDT)
|
|