Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

[NAV 2017 CU10] : Invoice rounding error

Posted on by 85

Hi,


I have discover a problem of rounding with the invoice treatment in NAV 2017 CU 10

I have a sales line :

6837.salesline.png

 

The unit price is 4.90, the discount 25 so the discount amount is 1.225 and the line amount is 4.90 – 1.225 = 3.675 and with rounding precision 3.68

 

When i launch the combine shipment, Line amout of the invoice is alway 3.68 but when i post my invoice there is a problem.

 

In my Sales Invoice Line the line amount is 3.67 beacause in the cu 80 there is this line :

code1.png

 

And the function GetLineAmountToHandle T37 :

4380.code.png

 

lineAmount = 4.9

LineDiscAmount = 4.9 * 25 /100 = 1.225 = 1.23 in EUROS CURRENCY

So my Line Amount in my  invoice is now : 4.9-1.23 = 3.67

 

In comment this is the code of CU6 or NAV 2015 and there isn’t this problem with this code.

*This post is locked for comments

  • Suggested answer
    Jens Glathe Profile Picture
    Jens Glathe 6,092 on at
    RE: [NAV 2017 CU10] : Invoice rounding error

    Hi Matthieu,

    that's what I meant with rounding issues. Multiplication and rounding is not order invariant. The original code looks like the right one. The inner rounding term is the line amount, which is ok if you have a case where you can't depend on the field "Line Amount" because of possible recursions/endless loops. The replacement code tries to calculate a different calculation path, which would be an equivalent if there where no roundings. With Quantity being decimal, you could end up with a non-rounded line discount amount, btw. So... best to revert to the original code.

    with best regards

    Jens

  • RE: [NAV 2017 CU10] : Invoice rounding error

    Ok thanks for your answer.

    The problem is on the sales line of my specific version. The line amount in Cronus Standard is 3.67.

    I don't know why a developer has to replace the standard code by this one :

    code3.png

    and the amount of the line is 3.68 on the sales line and it transforms to 3.67 in invoice.

  • Verified answer
    Jens Glathe Profile Picture
    Jens Glathe 6,092 on at
    RE: [NAV 2017 CU10] : Invoice rounding error

    Multiple rounding is always an issue. This appears to be the case here.

    The general rule is that you round all partial amounts per document line, and sum that up to the totals of the document. Addition is invariant to rounding, multiplication is not. Now, if you do a partial invoice, you're sort of in a quandary: You need to determine new line amount (and line discount amount), but the original line amounts are already rounded. And line discount % is calculated from line amount... what to do? It was done until NAV2017 CU08 (originally introduced on NAV2013 RTM):

        PROCEDURE GetLineAmountToHandle@117(QtyToHandle@1002 : Decimal) : Decimal;
        VAR
          LineAmount@1001 : Decimal;
          LineDiscAmount@1000 : Decimal;
        BEGIN
          IF "Line Discount %" = 100 THEN
            EXIT(0);
    
          GetSalesHeader;
          LineAmount := ROUND(QtyToHandle * "Unit Price",Currency."Amount Rounding Precision");
          LineDiscAmount := ROUND("Line Discount Amount" * QtyToHandle / Quantity,Currency."Amount Rounding Precision");
          EXIT(LineAmount - LineDiscAmount);
        END;

    As you can see, the LineAmount is calculated from the best precision available (new quantity * unit price), and rounded as it is a line amount. LineDiscAmount is calculated from the (already rounded) line discount amount, and rounded again. This could be probblematic. Better to do it the new way (NAV2017 CU09):

        PROCEDURE GetLineAmountToHandle@117(QtyToHandle@1002 : Decimal) : Decimal;
        VAR
          LineAmount@1001 : Decimal;
          LineDiscAmount@1000 : Decimal;
        BEGIN
          IF "Line Discount %" = 100 THEN
            EXIT(0);
    
          GetSalesHeader;
          LineAmount := ROUND(QtyToHandle * "Unit Price",Currency."Amount Rounding Precision");
          LineDiscAmount :=
            ROUND(
              LineAmount * "Line Discount %" / 100,Currency."Amount Rounding Precision");
          EXIT(LineAmount - LineDiscAmount);
        END;

    This code calculates the partial amounts from the best values available, and is rounded by the "Line Amount" rule. So... I would say this fix makes sense.

    Now to the issue that I see:

    [quote user="Matthieu Corvaisier"]

    6837.salesline.png

     

    The unit price is 4.90, the discount 25 so the discount amount is 1.225 and the line amount is 4.90 – 1.225 = 3.675 and with rounding precision 3.68

    [/quote]

    How are the fields in the page calculated? I don't have a French version here, so... are these custom fields? They need to be rounded the same way, all line amounts are already rounded, and you can only add/subtract them. So.. "Net Unit Price" would be "Unit Price" - round("Unit Price" * "Line Discount %" / 100, Currency."Unit-Amount Rounding Precision"). This value can be for information only, and is in unit-amount rounding precision. "Montant HT" (whatever HT means) would be round("Net Unit Price" * Quantity, Currency."Amount Rounding Precision"). This would show a net unit price of 3.675, and a line amount including discount of 3.68. But this is a forbidden shortcut, you need to take the two already rounded partial amounts, line amount and line discount amount. So, line amount including discount needs to be "Line Amount" - "Line Discount Amount". And yes, this will lead in this case to the counter-intuitive rounding down, as the discount amount is rounded up. But the whole application works this way. Microsoft actually fixed a double-rounding bug.

  • Suggested answer
    AJAnsari Profile Picture
    AJAnsari 5,754 on at
    RE: [NAV 2017 CU10] : Invoice rounding error

    Not to oversimplify this, but have you checked your General Ledger Setup > "Invoice Rounding Type" field to see if it is different in your NAV 2017 environment than it is in the other NAV 2015 environment you're comparing it with.

    It is typically set to Nearest, but you can set it to Up or Down, and that could force it to display 3.68 or 3.67 depending on what you choose.

    I hope this helps. If my response has answered your question, please verify by clicking Yes next to "Did this answer your question?"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans