[rules-users] using BigDecimal in rules

Libor Nenadál libor.nenadal at gmail.com
Mon Mar 16 10:50:45 EDT 2009


The problem with BigDecimal is this:
(new BigDecimal("43.0")).equals(new BigDecimal("43")) is evaluated to false
but
(new BigDecimal("43.0")).compareTo(new BigDecimal("43")) is evaluated to 0
=> they are equal

Note that you should use String in constructor instead of double otherwise
you get something unpredictable - see
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html#BigDecimal(double)

And because your evaluator uses equals, it is quite unusable. Is it possible
to do some special wrapper for this type? Just for equality, other
operations would be nice to look like "x * y" but with division you need to
specify scale and therefore I think it is not possible to wrap it to some
nice look. :-(

Regards,
Libor


Edson Tirelli-3 wrote:
> 
>    It sounds like a bug. Can you get Drools source code and look at the
> unit
> test for this to make sure your scenario works there? The file is:
> 
> drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
> 
>    Method is:
> 
> testBigDecimal()
> 
>    Very easy to add your use case in there.
> 
>    Let us know what you find.
> 
>    Edson
> 
> 

-- 
View this message in context: http://www.nabble.com/using-BigDecimal-in-rules-tp20362868p22539892.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list