[jboss-jira] [JBoss JIRA] Created: (JBRULES-2009) Use compareTo() instead of equals() with BigDecimal
Libor Nenadál (JIRA)
jira-events at lists.jboss.org
Tue Mar 17 05:28:22 EDT 2009
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: Mark Proctor
Priority: Minor
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