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 RE: Strange XSLT behaviour - Obliq apol for SOT
Date Tue, 10 Apr 2001 08:50:41 GMT
Well, for posterity and for anyone who requires the sort of rounding
behaviour I noted previously the following is a solution.

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

cheers!


-----Original Message-----
From: Robert Stuart [mailto:Robert.Stuart@NFER-NELSON.co.uk]
Sent: Tuesday, April 10, 2001 9:36 AM
To: 'general@xml.apache.org'
Subject: RE: Strange XSLT behaviour - Obliq apol for SOT


The argument should not be "is this rounding rule correct?", but "please,
may we have a selection of rounding rules".


>But what has summing to do with rounding? Not really intimately related are
they?

Very intimately if you are working with finance (this type of rounding is
sometimes called "Banker's Rounding").  Financial reports are frequently
presented to the nearest '000, (or '00, or '000000).


When presenting a financial report to managers; you will find some keen bod
who will add up the numbers and find that they are disagree with the total
presented at the bottom.  
This then takes explanation - which is painful even when the results are
correct.


This really is a matter of the culture you work for, and the use to which
the figures are put.
In an engineering environment, the standard rounding (as suggested by
yourself, by Java's Math.round, and taught me at school) is accepted, and
expected.


-----Original Message-----
From: Samson, Lyndon [IT] [mailto:lyndon.samson@ssmb.com]
Sent: 09 April 2001 17:23
To: 'general@xml.apache.org'
Subject: RE: Strange XSLT behaviour - Obliq apol for SOT



But what has summing to do with rounding? Not really intimatly related are
they?

The standed rules for rounding ie those used by java's Math.round;

System.out.println(Math.round(9.5));
System.out.println(Math.round(10.5));
System.out.println(Math.round(11.5));
System.out.println(Math.round(12.5));

produces;

10
11
12
13

...


-----Original Message-----
From: Robert Stuart [mailto:Robert.Stuart@NFER-NELSON.co.uk]
Sent: Monday, April 09, 2001 5:14 PM
To: 'general@xml.apache.org'
Cc: 'lyndon.samson@ssmb.com'
Subject: RE: Strange XSLT behaviour


Yes ... but
	9.5 + 10.5 + 11.5 + 12.5 = 34

	10 + 11 + 12 + 13 = 36	(ie wrong)

	10 + 10 + 12 + 12 = 34

Hence this type of rounding

-----Original Message-----
From: Samson, Lyndon [IT] [mailto:lyndon.samson@ssmb.com]
Sent: 09 April 2001 16:55
To: 'general@xml.apache.org'
Subject: RE: Strange XSLT behaviour


I would have expected

      9.5  => 10
      10.5 => 11
      11.5 => 12
      12.5 => 13

Ie what I remember to be standard rounding rules. I could probably work
around it
by adding 0.1 but thats a definitive 'dodgy hack' :-)



-----Original Message-----
From: Maksim Sakki [mailto:maksim.sakki@hansa.ee]
Sent: Monday, April 09, 2001 4:42 PM
To: 'general@xml.apache.org'
Subject: RE: Strange XSLT behaviour



Hi,

The given behaviour is exactly what you get when writing
"format-number(9.5,'00')".
If you want to format numbers keeping 2 decimal places, you should write
"format-number(9.5,'0.00')".

Maksim Sakki


-----Original Message-----
From: Samson, Lyndon [IT] [mailto:lyndon.samson@ssmb.com]
Sent: 09. aprill 2001. a. 17:34
To: general@xml.apache.org
Subject: Strange XSLT behaviour


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? 



[deleted]

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

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