RE: [xsl] Xalan Rounding

Subject: RE: [xsl] Xalan Rounding
From: "Nik Krimm" <Nik.Krimm@xxxxxxxxxxxxxxx>
Date: Fri, 10 May 2002 15:12:00 -0500
[ to all - sorry for the previous post - it got away before i was finished ]

Thanks Jeff and Stuart for the info and suggestions:

I think you are right on, Jeff when you suggested:

> what you are seeing is IEEE-754 round to nearest mode, 
> which says that ties are broken by rounding to an even value 

When I get 107.5, it rounds up to 108, when I get 106.5 it rounds down to 106.

I am loathe to use the rounding option because:
1. some of the numbers submitted to this template will have more decimal places (i.e. 1.065 --> result = 1.07)
2. i have tried multiplying by 100, then rounding, then dividing by 100 to solve [#1] for 2 decimal places, but occasionally get strange values  from the division, like 1.0649999999999999999999999999999999.

Pending a better solution, I have implemented a dreadful kludge - 

<xsl:value-of select="format-number($number +.000000001 ,$format)"/>

This causes 106.500000001 to round up to 107, and 1.060000001 to round up to 1.07, but 'yuk'.

Thanks again....

-----Original Message-----
From: Jeff Kenton [mailto:jkenton@xxxxxxxxxxxxx]
Sent: Friday, May 10, 2002 2:31 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Xalan Rounding

On Fri, 10 May 2002, Stuart Celarier wrote:

..Perform whatever rounding math you desire explicitly before passing the
..value to format-number:
..  format-number( round(//value), '##')

This will work, and solve his problem, but the spec is clear that 
format-number() should do that for him.  The XSLT 2.0 spec has the gory 
details, as does the Java spec referenced in the XSLT 1.0 spec.


Jeff Kenton
DataPower Technology, Inc.
**** Wire speed XSLT ****

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread