BigDecimal Rounding Issue

pav's Avatar

pav

Mar 21, 2013 @ 10:07 AM

Hi

I know the issue with rounding should have been fixed back in jbilling v2.2.xx however looks like it's still exist. The use of BigDecimal improved the accuracy but not fully.
Take this example:
I have an order with Item price of $139.90 and the Tax of 15% which gives me the total for the order incuding taxes of $160.88. 15% from 139.90 gives you $20.985 which should round up to $20.99 and give you a total for the order of $160.98.

Is there any quck fix that can be applied to sort this issue or most of the code have to be refactored to fix it?

Regards Pav

  1. Support Staff 1 Posted by Technical Suppo... on Apr 03, 2013 @ 01:41 PM

    Technical Support's Avatar

    Hello pav,

    That's an issue we have in some places of the application. Sometimes someone rounded UP and sometimes DOWN. We are constantly fixing this bugs so the only workaround you have today is to manually modify the code where you are having problems. If not, you should consider using a newer version of jBilling which has a lot of bug fixes together with new functionalities.

    Hope this helps.
    Let us know if we can assist you in any other way.

    Regards,

    jBilling Technical Support Team

  2. 2 Posted by pav on Apr 04, 2013 @ 10:09 AM

    pav's Avatar

    Hi

    I have tried new community edition 3.0.X the problem still there.

    As BigDecimal scale that is used for most calculation is 10 wich has to be inline with underlying SQL data type. Using BigDecimal.ROUND_HALF_UP will not round value(eg 20.9850000000) up. Please also note that Webservice objects are using 2 decimals scale which produces correct result.

  3. Support Staff 3 Posted by Technical Suppo... on Apr 15, 2013 @ 04:29 PM

    Technical Support's Avatar

    Hello pav,

    This issue is alredy logged as a bug and will be fixed as soon as possible. It appears when a tax or a late fee has been applied on an invoice.
    Let us know if you've encountered simmilar bug in other scenarios.

    Thanks for your feedback.
    Regards,
    jBilling Technical Support Team

  4. 4 Posted by pav on Apr 30, 2013 @ 12:48 PM

    pav's Avatar

    Orders has similar issue, logically I would assume with orders you would keep 10 decimal for more accurate calculation, however I think in presentation layer it should round up to 2 decimals.

    NotificationsBL uses Util.formatMoney() this should be updated to be:

    NumberFormat format = NumberFormat.getNumberInstance(locale);
      ((DecimalFormat) format).applyPattern(bundle.getString("format.float"));
    // round up Decimal
    ((DecimalFormat) format).setRoundingMode(RoundingMode.UP);

    Also during Invoce creation I dont think we need more then 2 decimal points for the totals and balances and should be:

    // ensure that there are only two decimals in the invoice
     if (newInvoice.getTotal() != null) { newInvoice.setTotal(newInvoice.getTotal().setScale(Constants.BIGDECIMAL_SCALE_STR, Constants.BIGDECIMAL_ROUND));
     }

    instead of Constants.BIGDECIMAL_SCALE
    Please not that above for invoice creation will still be incorrect if total equal for example $20.9848000000 rounded to $20.98 and should be $20.99.

    Not sure if better solution is just to fix taxing and late fees lines for orders the rest should should be fixed by itself.

  5. Support Staff 5 Posted by Technical Suppo... on Jan 20, 2015 @ 12:02 PM

    Technical Support's Avatar

    hello ,

    Please let us know with new ticket if your are still facing this issue.

    Thank you,
    jBilling Technical Support Team

  6. Technical Support closed this discussion on Jan 20, 2015 @ 12:02 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac