(- 1.1 0.9) ==> 0.20000000000000007
(- 1.1 0.7) ==> 0.40000000000000013
Any idea what the reason is or how can I fix it other than to round-
off in
the application.
This is a general property of the floating-point number system used
in Java (and many other languages); see, for example, http://
docs.sun.com/source/806-3568/ncg_goldberg.html . The basic idea is
that some numbers which can bre represented exactly in decimal
notation are repeating fractions in binary, and therefore can only be
represented approximately. Unfortunately, this includes multiples of
0.1 .
You can use Jess's "format" function for converting a number into a
string in a particular format; i.e.,
(format nil "%.2f" (- 1.1 0.7)) => "0.40"
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------