xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Samson, Lyndon [IT]" <lyndon.sam...@ssmb.com>
Subject Strange XSLT behaviour
Date Mon, 09 Apr 2001 15:34:05 GMT
Using xalan-j_2_0_0

I've noticed some funny behaviour in xalan.

When given this;

<xsl:value-of select="format-number(9.5,'00')"/> +
<xsl:value-of select="format-number(10.5,'00')"/> +
<xsl:value-of select="format-number(11.5,'00')"/> +
<xsl:value-of select="format-number(12.5,'00')"/>

It returns something like this;

10 + 10 + 12 + 12 

That is all the odd numbers are rounded up and even numbers are rounded
down.

The W3c spec refers to the java.text.DecimalFormat class

This test code;

	public void pNum(double num) {
        java.text.FieldPosition fp = new
java.text.FieldPosition(java.text.NumberFormat.FRACTION_FIELD);
        StringBuffer sb = new StringBuffer();
        java.text.DecimalFormat df = new java.text.DecimalFormat("00");
        sb = df.format(num, sb, fp);
        
	  System.out.println("SB:"+sb.toString());
	}


      pNum(9.5);
      pNum(10.5);
      pNum(11.5);
      pNum(12.5);

produces;

SB:10
SB:10
SB:12
SB:12
The same situation! The only question is this a bug or a feature? Maybe my
mathematical memory is faulty
and this is the standard way of rounding to integers? 



---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message