Hi Brian,

I tried your code in Xalan (C and J) and MSXML and got '2.79' (with the
digits after decimal point intact). The XSLT spec says that numbers are kept
in double format internally so you shouldn't be getting any truncation loss
as a result of doing math. The 'sum' function is also supposed to keep
numbers in their original format. The only culprit may be the xsl:value-of
instruction (although on my system, it's working fine). You might want to
try to force a format using something like:

<xsl:value-of select="format-number(sum(tax_item/amount),
'########.#########')" />

The '#' characters default to the formatting scheme defined in the JDK 1.1
java.text.DecimalFormat class
<http://java.sun.com/products/jdk/1.1/docs/api/java.text.DecimalFormat.html>
.

Hope this helps,
Ramin

>
>
> Sorry this is probably not the most appropriate forum, but I have looked
> everywhere I can think of. If anyone on this list can point me in
> the right
> direction I would be grateful.
> Thanks,
> Brian
> ----- Original Message -----
> From: "Brian T. Wolf" <[EMAIL PROTECTED]>
> Newsgroups: comp.text.xml
> Sent: Tuesday, November 27, 2001 2:04 PM
> Subject: xslt and number formats
>
>
> > OK, I am at my wits' end. I have looked at various sites, specs, and
> > FAQ's, and I just am not getting an understanding of number
> > formatting. I am using templates to transform my XML data into a table
> > after which I will have column totals. I am using the sum() function
> > and the math seems to be working as expected - with one minor hitch:
> > the decimals are being truncated. Since I am printing invoices dealing
> > with currency it is essential that the decimals remain down to the
> > penny. Can someone explain this in clear English for me, or else point
> > me somewhere I may not have yet seen?
> >
> > sample XML:
> > <taxes>
> >  <tax_item>
> >   <description>Federal Excise Tax</description>
> >   <amount>2.25</amount>
> >  </tax_item>
> >  <tax_item>
> >   <description>State 911 Emergency Tax</description>
> >   <amount>0.54</amount>
> >  </tax_item>
> > </taxes>
> >
> > sample XSL:
> > <xsl:template match="taxes">
> >  <!-- cut irrelevant table info -->
> >  <fo:table-row>
> >   <fo:table-cell>
> >    <fo:block>
> >     <xsl:value-of select="sum(tax_item/amount)"/>
> >    </fo:block>
> >   </fo:table-cell>
> >  </fo:table-row>
> >  <!-- other irrelevant table info -->
> > </xsl:template>
> >
> > I am using xalan-2.0.0 for the transformation, if that makes a
> > difference.
> >
> > Thanks much,
> > Brian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to