xsl-list
[Top] [All Lists]

Floating point error

2006-01-25 10:22:28
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>