RE: [xsl] Avoid rounding up/down in format-number function

Subject: RE: [xsl] Avoid rounding up/down in format-number function
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 2 Jan 2004 18:02:43 -0000
> 
> is there a way to avoid rounding up/down in the 
> format-number() function?
> 

format-number() is obliged to fit the number in the the space provided:
if your picture is "0.00##" then you will have at least two and at most
four digits after the decimal point.

That leaves the question of how the rounding is done. XSLT 1.0 specifies
the function in terms of the JDK 1.1 specification of DecimalFormat, and
the JDK 1.1 spec is notoriously vague. Later versions of the JDK have
specified that the rounding is "half-even" (i.e. 0.35 rounds to 0.4,
while 0.25 rounds to 0.2), but XSLT 1.0 processors are not obliged to
respect that.

Michael Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread