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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format