[OpenVPMS Developers] [JIRA] Created: (OBF-211) java.lang.ArithmeticException: Non-terminating decimal expansion; no exact repre
Key: OBF-211 URL: https://openvpms.atlassian.net/browse/OBF-211 Project: Business Framework Issue Type: Bug Affects Versions: 1.4 Reporter: Tim Anderson Assignee: Tim Anderson Priority: Minor Fix For: 1.5
The following code: {code} public void testDivide() { new JXPathHelper(); JXPathContext context = JXPathHelper.newContext(new Object()); context.getValue("7 div 3"); } {code} Yields the following exception: {noformat} java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1594) at org.openvpms.component.system.common.jxpath.BigDecimalOperationDivide.computeValue(BigDecimalOperationDivide.java:56) at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:323) at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:289) at org.openvpms.component.system.common.jxpath.BigDecimalTestCase.testDivide(BigDecimalTestCase.java:35) {noformat} This is because the BigDecimalOperationDivide.computeValue() method doesn't specity a scale and rounding mode for the division: {code} BigDecimal l = TypeConversionUtil.bigDecimalValue(args[0].computeValue(context)); BigDecimal r = TypeConversionUtil.bigDecimalValue(args[1].computeValue(context)); return l.divide(r); {code} It should be something like: {code} BigDecimal l = TypeConversionUtil.bigDecimalValue(args[0].computeValue(context)); BigDecimal r = TypeConversionUtil.bigDecimalValue(args[1].computeValue(context)); return l.divide(r, MathContext.DECIMAL128); {code} i.e a precision of 34 digits, and a rounding mode of HALF_EVEN
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://openvpms.atlassian.net/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________ OpenVPMS Developers Mailing List developers@lists.openvpms.org To unsubscribe or change your subscription visit: http://lists.openvpms.org/listinfo/developers Posts from this mailing list can be viewed online and replied to in the OpenVPMS Developer's forum- http://tinyurl.com/openvdf