I searched on the forum before I posted this and looked in JIRA. It appears
that all problems like this with BigDecimal are thought to be resolved.
However, I am having a problem that appears it may be attributed to Drools
using the BigDecimal( double ) constructor when converting decimal numbers
in the rules to a BigDecimal.
If you are able to reproduce this problem, what is the work around? Use an
eval statement?
The rule does not fire in the following test:
package org.test;
import java.math.BigDecimal;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatelessKnowledgeSession;
public class BigDTest {
public final static String RULE =
"package mypackage; " +
"import org.test.BigDTest;" +
"rule \"BigDecimal compare problem\" " +
" when " +
" BigDTest( bigDValue == 6.3 ) " +
" then " +
" System.out.println( \"Matched!\" ); " +
" end"
;
private BigDecimal bigDValue = new BigDecimal( "6.3" ) ; // Rule will fire
if this is changed to BigDecimal( 6.3 )
public BigDecimal getBigDValue() {
return bigDValue;
}
public void setBigDValue( BigDecimal bigDValue ) {
this.bigDValue = bigDValue;
}
public static void main( String[] args ) {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( RULE.getBytes() ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
BigDTest bigDTest = new BigDTest();
ksession.execute( bigDTest );
}
}
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Problems-with-BigDeci...
Sent from the Drools - User mailing list archive at
Nabble.com.