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

Floating point error

Subject: Floating point error
From: "Thang X. Le" <tle@xxxxxxxxxxx>
Date: Wed, 25 Jan 2006 09:22:28 -0800
floating point error
Hi,

I just have a simple problem but can't seem to find the
solution. Given this xml structure:
<product>
   <quantity>3000</quantity>
   <price>6.4</price>
</product>
(the actual quantity and price may vary, but they're always
valid numbers).
I just have to compute the total price, which is:
<xsl:value-of select="format-number(price * quantity,'0.00')"/>

But the floating point number calculation is arbitrarily incorrect.
I may get 19199.91, or 19200. Similarly with other values of
price and quantity. It seems the incorrect result appears at
random.
Even if I try to round off price beforehand, nothing changes:
<xsl:value-of select="format-number(format-number(price, '0.0') * quantity,'0.00')"/>

I'm using dom4j, Java 1.4.1, SunOS. On Windows the calculations
appear to be correct.
So, is it an OS thing? Is there any workaround?
Thanks,

Thang Le

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.