My guess would be that the double is being typecast into a long before the comparison is made?

Try switching the logic round so you do dbl < lo

 

Thomas

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Miles Wen
Sent: 04 March 2011 02:59
To: rules-users@lists.jboss.org
Subject: [rules-users] 'Long' and 'double' value comparing problem in drools 5.1.0

 

hi there,

I have a simple fact class:

 

public class Msg {

    private Long lo = 5l;

    private double dbl = 5.5;

 

    public Long getLo() {

        return lo;

    }

 

    public void setLo(Long lo) {

        this.lo = lo;

    }

 

    public double getDbl() {

        return dbl;

    }

 

    public void setDbl(double dbl) {

        this.dbl = dbl;

    }

}

 

and a simple drl program:

 

package com.sample

 

import com.sample.Msg;

 

rule "Hello World"

          when

                      m:Msg(lo >= dbl)        

          then

                      System.out.println( "hello world" );

                      System.out.println(m.getLo());

                      System.out.println(m.getDbl());

end

 

I simply compare the Long value, which is 5, to the double value ,which is 5.5, with operator '>=', and the output is:

 

hello world

5

5.5

 

but it can't be ,cause 5 is less than 5.5.

then I modified the drl program a bit:

 

m:Msg(lo == dbl)

 

It successfully prints out the message as well.It seems that drools treated the double value '5.5' as '5' in comparing... 

Is this a bug or something?What could I do to correct it?

thanks.




**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************