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

RE: basic math functions: problem with substraction re

Subject: RE: basic math functions: problem with substraction result (newbie question)
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 13 Aug 2003 12:07:48 +0100
math substraction
This problem occurs because 2.4 and 0.2 cannot be represented precisely
as IEEE floating point numbers, so you get rounding errors. The solution
is to display the result using format-number, which rounds it to the
required precision, for example

format-number(2.4 - 0.2, "#0.00")

will display the result to two decimal places.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Nicolas Stern
> Sent: 13 August 2003 10:09
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  basic math functions: problem with 
> substraction result (newbie question)
> 
> 
> Hi - many thanks in advance for any help on the following problem:
> 
> Can anyone explain me the following behavior with basic math 
> functions ?
> 
> I'm doing additions and substractions in an xsl sheet, and 
> don't get the 
> expected results.
> 
> my xml file: (dummy.xml)
> -------------------------------
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="t2.xslt"?>
> <ROWSET>
>     <ROW>dummy</ROW>
> </ROWSET>
> -------------------------------
> the stylesheet: (t2.xslt)
> -------------------------------
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:variable name="var1" select="2.4" />
> <xsl:variable name="var2" select="0.2" />
> <xsl:template match="/">
>   <html>
>       <ul>
>           <li><xsl:value-of select="$var1 + $var2" /></li>
>           <li><xsl:value-of select="$var1 - $var2" /></li>
>       </ul>
>     <hr />
> 
>   </html>
> </xsl:template>
> </xsl:stylesheet>
> -------------------------------
> the output: (using msxsl dummy.xml t2.xslt
> -------------------------------
> < h t m l >
> < u l >
> < l i > 2 . 6 < / l i >
> < l i > 2 . 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 7 < / l i >
> < / u l >
> < h r >
> < / h t m l >
> -------------------------------
> 
> I would need the result of $var1 - $var2 to be = 2.2, as expected
> 
> The behavior is identical when using the parser in xmlspy.
> 
> Any hint ?
> 
> thanks in advance
> 
> Nicolas
> 
> _________________________________________________________________
> MSN Search, le moteur de recherche qui pense comme vous !  
> http://search.fr.msn.ch
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 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.