<p>FYI, 5.4 (beta 2) allows you to use B and I as BigDecimal and BigInteger respectively in LHS DRL (and RHS if using MVEL) so you can write:</p>
<p>MyFact( myBigDecimal == 99.9B )</p>
<p>sent on the move</p>
<p>On 27 Mar 2012 08:16, "Wolfgang Laun" <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 27/03/2012, Zeke <<a href="mailto:xanadu860122@gmail.com">xanadu860122@gmail.com</a>> wrote:<br>
> Whether the comparison is precarious or not should depend on how you handle<br>
> the literal. If you handle 99.9 as BigDecimal("99.9") which precision can<br>
> be controlled, you can trust the comparison.<br>
><br>
<br>
Wait a sec: primarily, you are testing a double, and this is where<br>
some unavoidable imprecision is introduced. These are some doubles<br>
close<br>
to 99.9:<br>
<br>
a 99.899999999999990000 0x1.8f99999999999p6<br>
b 99.900000000000000000 0x1.8f9999999999ap6<br>
c 99.900000000000020000 0x1.8f9999999999bp6<br>
<br>
a < 99.9 is the true value truncated, b > 99.9 is rounded (the next<br>
binary digit being 1). There just isn't a double == 99.9. (Don't be<br>
confused by b's printed value.)<br>
<br>
The BigDecimal value 99.90000000000001 you have observed is due to<br>
rounding the result of new BigDecimal( (double)99.9 ), i.e.<br>
99.900000000000005684341886080801486968994140625<br>
<br>
It's easy to see that a better value is obtained by using a String value:<br>
new BigDecimal( "99.9" )<br>
but I don't know whether your Drools version would let you write<br>
doubleValue == "99.9".<br>
<br>
<br>
If you want/have to stick with 4.x you might use public static final<br>
doubles defined in some Java class instead of the magic 99.9. This<br>
should avoid the sidestep into BigDecimal and the ensuing conversion<br>
confusion.<br>
<br>
-W<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></p>