Saturday, May 6, 2023

Convert Amount in Indian Format (INR Format) in Business Central

 Hello Friends,

Recently i have developed one small function which convert any amount in Indian Amount Format Style (Digit grouing of amount as Crore, Lakh and Thousand)

For example:

Amount: 999,999.23  will show as 9,99,999.23

Use below CAL Function which take input as Decimal Value and Return amount in INR Format:

procedure GetIndianFormat_gFnc(Amount_iDec: Decimal) RtnValue: Text[50]
    var
        AddMinuSIng_lBln: Boolean;
        i: Integer;
        FromAmt_lDec: Decimal;
        ToAmt_lDec: Decimal;
    begin
        if Amount_iDec < 0 then
            AddMinuSIng_lBln := true;

        Amount_iDec := Abs(ROUND(Amount_iDec, 0.01));
        if Amount_iDec <= 99999.99 then begin  // 1 Lakh
            if AddMinuSIng_lBln then
                RtnValue := '-' + Format(Amount_iDec, 0,
'<Precision,2><sign><Integer Thousand><Decimals,3>')
            else
                RtnValue := Format(Amount_iDec, 0,
'<Precision,2><sign><Integer Thousand><Decimals,3>');

            exit(RtnValue);
        end;

        if Amount_iDec <= 9999999.99 then begin
            for i := 1 to 99 do begin
                FromAmt_lDec := i * 100000;
                ToAmt_lDec := FromAmt_lDec + 99999.99;

                if (Amount_iDec >= FromAmt_lDec) and (Amount_iDec <= ToAmt_lDec) then begin
                    Amount_iDec := Amount_iDec - FromAmt_lDec;

                    if AddMinuSIng_lBln then
                        RtnValue := '-' + Format(i) + ',' + Format(Amount_iDec, 0,
'<Precision,2><sign><Integer Thousand><Decimals,3>')
                    else
                        RtnValue := Format(i) + ',' + Format(Amount_iDec, 0,
'<Precision,2><sign><Integer Thousand><Decimals,3>');

                    exit(RtnValue);
                end;
            end;
        end;

        if Amount_iDec > 9999999.99 then begin
            for i := 1 to 99 do begin
                FromAmt_lDec := i * 10000000;
                ToAmt_lDec := FromAmt_lDec + 9999999.99;

                if (Amount_iDec >= FromAmt_lDec) and (Amount_iDec <= ToAmt_lDec) then begin
                    Amount_iDec := Amount_iDec - FromAmt_lDec;

                    if AddMinuSIng_lBln then
                        RtnValue := '-' + Format(i) + ',' + GetIndianFormat_gFnc(Amount_iDec)
                    else
                        RtnValue := Format(i) + ',' + GetIndianFormat_gFnc(Amount_iDec);

                    exit(RtnValue);
                end;
            end;
        end;

        Error('Input Value %1 Invalid', Amount_iDec);
    end;

7 comments:

  1. https://ispl13-my.sharepoint.com/:u:/g/personal/nileshg_intech-systems_com/Eflg4epOC-RFkrBV0cdwgxIBmD6WJMRGwcMamjXpGh88FQ?e=h8pcDO

    ReplyDelete
  2. CREATE TABLE [dbo].[$ndo$srvproperty](

    ReplyDelete
  3. An unexpected error occurred after a database command was cancelled.

    ReplyDelete
  4. https://community.dynamics.com/business/f/dynamics-365-business-central-forum/462623/an-unexpected-error-occurred-after-a-database-command-was-cancelled#:~:text=An%20unexpected%20error%20occurred%20after%20a%20database%20command%20was%20cancelled.,-Suggested%20Answer&text=Hello-,1%2D%20make%20sure%20that%20NAV%2FBC%20service%20is%20in%20running,input%20the%20instance%20name%20correctly.

    ReplyDelete
  5. https://ispl13-my.sharepoint.com/:u:/g/personal/nileshg_intech-systems_com/EaVCmgI0B9FCnjZwGqsUlLoB-pN6DqxFB2M8Eb7VXddyTw?e=uaRUCa

    ReplyDelete
  6. https://ispl13.sharepoint.com/:u:/s/D365BC_ALProject_Source_ISPL/EUEUBmjcen5Dlr_A-jwBbK0B07qvve-OI3PJg1tdV8b_uw?e=CUh9zS

    ReplyDelete