[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

format-number abd numerical truncation

Subject: format-number abd numerical truncation
From: "Nunnington, John" <johnn@xxxxxxxxx>
Date: Thu, 28 Aug 2003 16:42:44 +0100
xsl format number
Hi All,

 

[2 part problem] 

 

We've encountered a problem with format-number where-by the value part
actually changes according to the precision.

 

XML:

<?xml version="1.0" encoding="UTF-8"?>
<AR_ITEMS elem="4">
   <EVENTS elem="1">
      <TOTAL elem="826">
         <AMOUNT>0.00000073173</AMOUNT>
      </TOTAL>
   </EVENTS>
   <EVENTS elem="2">
      <TOTAL elem="826">
         <AMOUNT>0.0000073173</AMOUNT>
      </TOTAL>
   </EVENTS>
   <EVENTS elem="3">
      <TOTAL elem="826">
         <AMOUNT>0.000073173</AMOUNT>
      </TOTAL>
   </EVENTS>
   <EVENTS elem="4">
      <TOTAL elem="826">
         <AMOUNT>0.73173</AMOUNT>
      </TOTAL>
   </EVENTS>
   <EVENTS elem="5">
      <TOTAL elem="826">
         <AMOUNT>0.073173</AMOUNT>
      </TOTAL>
   </EVENTS>
   <EVENTS elem="6">
      <TOTAL elem="826">
         <AMOUNT>0.00073173</AMOUNT>
      </TOTAL>
   </EVENTS>
</AR_ITEMS>



XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <xsl:output method="html" indent="yes"/>
   <!-- Main Driver Template -->
      <xsl:decimal-format zero-digit="0" decimal-separator="." name="df"
grouping-separator="," per-mille="," pattern-separator=";">
      </xsl:decimal-format>   
      <xsl:strip-space elements="*"></xsl:strip-space>
      <xsl:template match="/">
         <html>
         <HEAD>
         </HEAD>
         <body bgcolor="#ffffff">
            <table bgcolor="#cfcfcf" cellpadding="5" cellspacing="2"
border="1">
      <tbody>
         <xsl:for-each select="//EVENTS">
            <tr>
               <TD align="right">
                  <FONT size="3">
                     <xsl:if test="TOTAL[@elem  = 826]">
                        <xsl:value-of
select="format-number(TOTAL/AMOUNT,'0.0000')"/>
                     </xsl:if>
                  </FONT>
               </TD>
            </tr>
         </xsl:for-each>
      </tbody>
   </table>
   </body>
   </html>
   </xsl:template>
</xsl:stylesheet>

 

Resulting HTML:

 

0.0000
0.0000
0.1000
0.7317
0.7320
0.7000
 

 

....we never fixed this so we though that we'd correct the rounding in the
source program. This worked OK, as long as we had a full complement of
digits after the decimal point. When we have a number with less, say 0.7320,
it is being displayed at 0.732

 

Anybody ever comes across either of these problems and resolved them or
found them to be persistent bugs?



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.