BigDecimalComparisons

    If you have an object property of type BigDecimal (and this property is exposed through a getter that returns a BigDecimal), building rules that compare this property is a little tricky as the comparison will default to a string-comparison which is not very useful in most cases, or will result in a ClassCastException if you try to compare to a numeric.

     

    NOTE: in trunk, this has been changed to support BigDecimal and BigInteger directly. this will NOT be rolled into the 3.0.x branch, but be in the next major release.

     

    Assume the following:

     

    public class AnObject {
    
         private BigDecimal theBD;
    
         public BigDecimal getTheBD() {
              return theBD;
         }
    
    }
    

     

    And the following rule(which will not work and give a ClassCastException)

     

    rule "Bigger"
         when
              m : AnObject(theBD >= 0)
         then
              System.out.println( "Greater than 0" ); 
    end
    

     

    The comparison should be done as follow:

     

    rule "Bigger"
         when
              

    m : AnObject(v:theBD -> (v.doubleValue() >= 0))

     

     

         then
              System.out.println( "Greater than 0" ); 
    end