[jboss-jira] [JBoss JIRA] Resolved: (JBRULES-2009) Use compareTo() instead of equals() with BigDecimal

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Tue Apr 7 20:38:27 EDT 2009


     [ https://jira.jboss.org/jira/browse/JBRULES-2009?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Edson Tirelli resolved JBRULES-2009.
------------------------------------

    Resolution: Done


Fixed on revision #25878

http://fisheye.jboss.org/changelog/JBossRules/trunk/drools-core/src/main/java/org/drools/base/evaluators?cs=25878

> Use compareTo() instead of equals() with BigDecimal
> ---------------------------------------------------
>
>                 Key: JBRULES-2009
>                 URL: https://jira.jboss.org/jira/browse/JBRULES-2009
>             Project: JBoss Drools
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: drools-core
>            Reporter: Libor Nenadál
>            Assignee: Edson Tirelli
>            Priority: Minor
>             Fix For: 5.0.0.GA
>
>
> Currently BigDecimals are compared using equals() and the problem is following:
> (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. :-( The con is that compareTo() ignores scale but for common usage scenarios it should not matter.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the jboss-jira mailing list