Re: [xsl] format-number incorrectly formatting number (using fop 0.91beta)

Subject: Re: [xsl] format-number incorrectly formatting number (using fop 0.91beta)
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 Apr 2006 07:05:59 -0400
At 2006-04-18 20:27 +1000, Ian & Chris wrote:
 I am currently trying to format a large number (19v2) in a report, the
format-number function seems to do incorrect formatting when it deals with
large numbers, and an example follows:

<xsl:value-of select='format-number(-34567890123456787.00,"###,###.00
;###,###.00CR")'/>

In the above example the number should read

34,567,890,123,456,787.00CR

But when it formats it is set to:

34,567,890,123,456,788.00CR

I note that two different Java-based processors implement identical results ... so my guess is this is a Java issue and not an XSLT issue:


T:\ftemp>xslt-xalan ian.xsl ian.xsl con
34,567,890,123,456,780.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,788.00CR
34,567,890,123,456,788.00CR
4,567,890,123,456,781.00CR
4,567,890,123,456,782.00CR
4,567,890,123,456,783.00CR
4,567,890,123,456,784.00CR
4,567,890,123,456,785.00CR
4,567,890,123,456,786.00CR
4,567,890,123,456,787.00CR
4,567,890,123,456,789.00CR

T:\ftemp>xslt-saxon ian.xsl ian.xsl con
34,567,890,123,456,780.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,784.00CR
34,567,890,123,456,788.00CR
34,567,890,123,456,788.00CR
4,567,890,123,456,781.00CR
4,567,890,123,456,782.00CR
4,567,890,123,456,783.00CR
4,567,890,123,456,784.00CR
4,567,890,123,456,785.00CR
4,567,890,123,456,786.00CR
4,567,890,123,456,787.00CR
4,567,890,123,456,789.00CR

T:\ftemp>type ian.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
<xsl:value-of select='format-number(-34567890123456781.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456782.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456783.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456784.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456785.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456786.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456787.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-34567890123456789.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456781.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456782.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456783.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456784.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456785.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456786.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456787.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
<xsl:value-of select='format-number(-4567890123456789.00,"###,###.00
;###,###.00CR")'/><xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>

Any ideas, OK it is a large number, and you might say well you would never
use this, but, in insurance companies in Indonesia the numbers for
re-insurance in the local currency (rupiah). It may get to many billions for
a year.

Change to a non-Java implementation of XSLT.


How many XSLT implementations have you tried? Looking at the XSLT specification, XPath 1.0 Section 3.5 states the numbers are double-precision 64-bit IEEE 754 number ... which would surely handle the number you have.

That section makes reference to the Java Language Specification section 4.2.3.

http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#9208

XSLT Section 12.3 makes reference to decimal formatting:

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html

I hope this helps.

. . . . . . . . . . Ken

--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
Also for XML/XSLT/XSL-FO training:Birmingham,England 2006-05-22/25
Also for XSLT/XSL-FO training:    Copenhagen,Denmark 2006-05-08/11
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread