Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-249

Re-factor BigDecimal calculations

    XMLWordPrintableJSON

Details

    Description

      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);

      Attachments

        Activity

          People

            jleroux Jacques Le Roux
            jacopoc Jacopo Cappellato
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: