Re-factor BigDecimal calculations
--------------------------------- Key: OFBIZ-249 URL: http://issues.apache.org/jira/browse/OFBIZ-249 Project: OFBiz (The Open for Business Project) Issue Type: Bug Components: accounting, order Reporter: Jacopo Cappellato Copy of a set of related issues created in the old server by Si (and others): 1. In applications/accounting/src/ re-factor to use arithmetic.properties instead of 2. Per comments of Bradley Plies, The following files have something like: ... = new BigDecimal("0"); \applications\accounting\src\org\ofbiz\accounting \invoice\InvoiceServices.java (11 matches) \invoice\InvoiceWorker.java (4 matches) \payment\PaymentWorker.java \tax\TaxAuthorityServices.java \applications\accounting\webapp\accounting\WEB-INF\actions\invoice\createItemList.bsh (4 matches) \applications\order\src\org\ofbiz\order \order\OrderReadHelper.java \order\OrderReturnServices.java \shoppingcart\CheckOutHelper.java However BigDecimal already provides a constant BigDecimal.ZERO (as well as BigDecimal.ONE which are both inherited from superclass BigInteger) such that doing this is unnecessary (but not incorrect) and just creates more objects. The scale of the mathematical results will not be unaffected, as described in the JDK. http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html All Comments Work Log Change History Sort Order: [navigator.ascending.order] Comment by Leon Torres [08/Mar/06 12:33 PM] [ Permlink ] There is no BigDecimal.ZERO. I tried compiling, got an error, looked at the javadoc and realized it is only BigInteger.ZERO. We're better off setting a static ZERO ourselves somewhere, preferably at the top of the Java file along with the scale and rounding mode. Look at InvoiceServices.java for example. Also, I was setting the scale of zero out of paranoia in that code, it probably isn't necessary. =================================================== Re-factor the following to use arithmetic.properties instead of setting them directly: org/ofbiz/accounting/tax/TaxAuthorityServices.java: taxTotal.setScale(2, BigDecimal.ROUND_CEILING); org/ofbiz/accounting/tax/TaxAuthorityServices.java: priceWithTax.setScale(2, BigDecimal.ROUND_CEILING); org/ofbiz/accounting/invoice/InvoiceWorker.java: invoiceTotal = invoiceTotal.add( amount.multiply(quantity)).setScale(2,4); -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
[ http://issues.apache.org/jira/browse/OFBIZ-249?page=comments#action_12445008 ]
Leon Torres commented on OFBIZ-249: ----------------------------------- As part of this issue, do the following refactoring: Define UtilNumber.BD_ZERO = new BigDecimal("0"); Replace all instances of ZERO throughout the codebase with UtilNumber.BD_ZERO > Re-factor BigDecimal calculations > --------------------------------- > > Key: OFBIZ-249 > URL: http://issues.apache.org/jira/browse/OFBIZ-249 > Project: OFBiz (The Open for Business Project) > Issue Type: Bug > Components: accounting, order > Reporter: Jacopo Cappellato > > Copy of a set of related issues created in the old server by Si (and others): > 1. In applications/accounting/src/ re-factor to use arithmetic.properties instead of > 2. Per comments of Bradley Plies, > The following files have something like: > ... = new BigDecimal("0"); > \applications\accounting\src\org\ofbiz\accounting > \invoice\InvoiceServices.java (11 matches) > \invoice\InvoiceWorker.java (4 matches) > \payment\PaymentWorker.java > \tax\TaxAuthorityServices.java > \applications\accounting\webapp\accounting\WEB-INF\actions\invoice\createItemList.bsh (4 matches) > \applications\order\src\org\ofbiz\order > \order\OrderReadHelper.java > \order\OrderReturnServices.java > \shoppingcart\CheckOutHelper.java > However BigDecimal already provides a constant BigDecimal.ZERO (as well as BigDecimal.ONE which are both inherited from superclass BigInteger) such that doing this is unnecessary (but not incorrect) and just creates more objects. The scale of the mathematical results will not be unaffected, as described in the JDK. http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html > All Comments Work Log Change History Sort Order: [navigator.ascending.order] > Comment by Leon Torres [08/Mar/06 12:33 PM] > [ Permlink ] > There is no BigDecimal.ZERO. I tried compiling, got an error, looked at the javadoc and realized it is only BigInteger.ZERO. We're better off setting a static ZERO ourselves somewhere, preferably at the top of the Java file along with the scale and rounding mode. > Look at InvoiceServices.java for example. Also, I was setting the scale of zero out of paranoia in that code, it probably isn't necessary. > =================================================== > Re-factor the following to use arithmetic.properties instead of setting them directly: > org/ofbiz/accounting/tax/TaxAuthorityServices.java: taxTotal.setScale(2, BigDecimal.ROUND_CEILING); > org/ofbiz/accounting/tax/TaxAuthorityServices.java: priceWithTax.setScale(2, BigDecimal.ROUND_CEILING); > org/ofbiz/accounting/invoice/InvoiceWorker.java: invoiceTotal = invoiceTotal.add( amount.multiply(quantity)).setScale(2,4); -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |
Free forum by Nabble | Edit this page |