You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Anurag Meshram (JIRA)" <ji...@apache.org> on 2007/05/03 12:44:15 UTC

[jira] Commented: (OFBIZ-249) Re-factor BigDecimal calculations

    [ https://issues.apache.org/jira/browse/OFBIZ-249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12493334 ] 

Anurag Meshram commented on OFBIZ-249:
--------------------------------------

we declared the following in arithmatic.properties
 UtilNumber.BD_ZERO = new BigDecimal("0");

Now we got the problem with following line:
What does it mean - Replace all instances of "ZERO" throughout the codebase with "UtilNumber.BD_ZERO" ?

In .java file we implemented for this issue as follows
We changed the statement 
private static BigDecimal ZERO = new BigDecimal("0");   
into :
private static BigDecimal ZERO = UtilNumber.getNewBigDecimal("UtilNumber.BD_ZERO");

we write the method in UtilNumber.java  getNewBigDecimal(String)  which returns BigDecimal

Is it a correct scenario????


> Re-factor BigDecimal calculations
> ---------------------------------
>
>                 Key: OFBIZ-249
>                 URL: https://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.
-
You can reply to this email to add a comment to the issue online.