[rules-users] [rules user] different behavior on double type

Wolfgang Laun wolfgang.laun at gmail.com
Thu Apr 5 01:52:53 EDT 2012


A Java double literal: 99.9 is a double that does not represent the real
number 99.9 exactly. The Java String literal "99.9" is the accurate
decimal notation of the real number 99.9.

Conversions from 99.9+/-epsilon to a BigDecimal aren't likely to
produce a value that represent the real number 99.9 exactly - unless
you use a constructor with a MathContext defining the precision for
rounding.

Avoid mixing double and BigDecimal.

-W


On 05/04/2012, Zeke <xanadu860122 at gmail.com> wrote:
> Thanks for all your replies. I'm sorry for bring up this issue again. I
> tried the Drools 5.3.0.Final. For float and double type, I think current
> behavior is what I need. But for BigDecimal type, when my condition is "bd
> == 99.9" ("bd" equals new BigDecimal("99.9")), the condition is false. But
> if I add quotes to the literal as bd == "99.9", the condition will be true.
> Is this behavior is designed to be so? It seems 99.9 will be considered as
> double value, while "99.9" will be considered as a BigDecimal value.
>
> Thanks!
>



More information about the rules-users mailing list