[rules-users] Re: BigDecimal is Int or Long?
Geoffrey De Smet
ge0ffrey.spam at gmail.com
Thu Mar 27 03:19:41 EDT 2008
I personally wouldn't recommend accumulate's or mvel functions for
financial data in drools 4.0.5. Just try this code:
java.math.BigDecimal a = new java.math.BigDecimal("45.1");
java.math.BigDecimal b = new java.math.BigDecimal("40.0");
double c = a.doubleValue() - b.doubleValue();
return new java.math.BigDecimal(c);
(java.math.BigDecimal) 5.10000000000000142108547152020037174224853515625
More info at: http://jira.jboss.org/jira/browse/JBRULES-1322
With kind regards,
Geoffrey De Smet
Mark Proctor schreef:
> ST wrote:
>> Hi,
>>
>> There is a situation where BigDecimal is returned from a function.
>> But when
>> this BigDecimal is included as one of the conditions in a rule. I get a
>> ClassCastException about trying to cast to Integer. Below is an
>> example that
>> reproduces this error. Is this an expected behavior? If so, is there
>> any way
>> to avoid the error?
>>
> Ths is a known MVEL "feature". MVEL will narrow the value to what it
> thinks is an appropriate value. There is no current workaround, I'm
> discussing with the MVEL author on how we can address this for Drools in
> the future.
>>
>>
>> package com.sample
>>
>> import java.math.BigDecimal
>>
>>
>> rule "init1"
>> salience 1000
>> when
>> num : BigDecimal() from getBigDecimal("1")
>> then
>> System.out.println(num.compareTo(new BigDecimal("0")));
>> end
>>
>>
>> function BigDecimal getBigDecimal(String value) {
>> return new BigDecimal(value);
>> }
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list