Skip to main content

Amount in Words (International & Local Number system) in Business Central

 Hi Readers,

As some of our clients require to Print Amount on Reports in International Number System. Here we use periods like ones, thousand and millions etc.

Suppose, let us understand the International system by using number 1: ones (1), tens (10), hundreds (100), one thousands (1000), ten thousands (10000), hundred thousands (100,000), one millions (1,000,000), ten millions (10,000,000), hundred millions (100,000,000), etc. Here we place the numbers according to their place value.

So, here we have created new check Report which contains functions for both International as well as local No. system:

//TTC_KH_12012021_US and IN version
report 50004 "Check Customize"
{
    Caption = 'Check Customize';
    ProcessingOnly = true;
    dataset
    {
        dataitem(IntegerInteger)
        {
            column(Number; Number)
            {
            }
        }
    }
    var
        Text024: Label 'XXXX.XX';
        Text025: Label 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
        Text026: Label 'ZERO';
        Text027: Label 'HUNDRED';
        Text028: Label 'AND';
        Text029: Label '%1 results in a written number that is too long.';
        Text030: Label ' is already applied to %1 %2 for customer %3.';
        Text031: Label ' is already applied to %1 %2 for vendor %3.';
        Text032: Label 'ONE';
        Text033: Label 'TWO';
        Text034: Label 'THREE';
        Text035: Label 'FOUR';
        Text036: Label 'FIVE';
        Text037: Label 'SIX';
        Text038: Label 'SEVEN';
        Text039: Label 'EIGHT';
        Text040: Label 'NINE';
        Text041: Label 'TEN';
        Text042: Label 'ELEVEN';
        Text043: Label 'TWELVE';
        Text044: Label 'THIRTEEN';
        Text045: Label 'FOURTEEN';
        Text046: Label 'FIFTEEN';
        Text047: Label 'SIXTEEN';
        Text048: Label 'SEVENTEEN';
        Text049: Label 'EIGHTEEN';
        Text050: Label 'NINETEEN';
        Text051: Label 'TWENTY';
        Text052: Label 'THIRTY';
        Text053: Label 'FORTY';
        Text054: Label 'FIFTY';
        Text055: Label 'SIXTY';
        Text056: Label 'SEVENTY';
        Text057: Label 'EIGHTY';
        Text058: Label 'NINETY';
        Text059: Label 'THOUSAND';
        Text060: Label 'MILLION';
        Text061: Label 'BILLION';
        Text1280000: Label 'LAKH';
        Text1280001: Label 'CRORE';
        OnesText: array[20of Text[50];
        TensText: array[10of Text[50];
        ExponentText: array[5of Text[50];
    //TTC_KH_AmountInWords_USversion_START
    procedure InitTextVariable_USversion()
    begin
        OnesText[1] := Text032;
        OnesText[2] := Text033;
        OnesText[3] := Text034;
        OnesText[4] := Text035;
        OnesText[5] := Text036;
        OnesText[6] := Text037;
        OnesText[7] := Text038;
        OnesText[8] := Text039;
        OnesText[9] := Text040;
        OnesText[10] := Text041;
        OnesText[11] := Text042;
        OnesText[12] := Text043;
        OnesText[13] := Text044;
        OnesText[14] := Text045;
        OnesText[15] := Text046;
        OnesText[16] := Text047;
        OnesText[17] := Text048;
        OnesText[18] := Text049;
        OnesText[19] := Text050;

        TensText[1] := '';
        TensText[2] := Text051;
        TensText[3] := Text052;
        TensText[4] := Text053;
        TensText[5] := Text054;
        TensText[6] := Text055;
        TensText[7] := Text056;
        TensText[8] := Text057;
        TensText[9] := Text058;

        ExponentText[1] := '';
        ExponentText[2] := Text059;
        ExponentText[3] := Text060;
        ExponentText[4] := Text061;
    end;


    procedure FormatNoText_USversion(var NoText: array[2of text; No: Decimal
    CurrencyCode: Code[10])
    var
        PrintExponent: Boolean;
        Ones: Integer;
        Tens: Integer;
        Hundreds: Integer;
        Exponent: Integer;
        NoTextIndex: Integer;
        DecimalPosition: Decimal;
    begin
        CLEAR(NoText);
        NoTextIndex := 1;
        //TTC_KH
        //NoText[1] := '****';
        NoText[1] := '';
        // GLSetup.GET;

        IF No < 1 THEN
            AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, Text026)
        ELSE
            FOR Exponent := 4 DOWNTO 1 DO BEGIN
                PrintExponent := FALSE;
                Ones := No DIV POWER(1000, Exponent - 1);
                Hundreds := Ones DIV 100;
                Tens := (Ones MOD 100) DIV 10;
                Ones := Ones MOD 10;
                IF Hundreds > 0 THEN BEGIN
                    AddToNoText_USversion(NoText, NoTextIndex, PrintExponent,
                    OnesText[Hundreds]);
                    AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, Text027);
                END;
                IF Tens >= 2 THEN BEGIN
                    AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                    TensText[Tens]);
                    IF Ones > 0 THEN
                        AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                        OnesText[Ones]);
                END ELSE
                    IF (Tens * 10 + Ones0 THEN
                        AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                        OnesText[Tens * 10 + Ones]);
                IF PrintExponent AND (Exponent > 1THEN
                    AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                    ExponentText[Exponent]);
                No := No - (Hundreds * 100 + Tens * 10 + Ones
                POWER(1000, Exponent - 1);
            END;

        AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, Text028);
        DecimalPosition := GetAmtDecimalPosition_USversion;
        //TTC_KH
        //AddToNoText(NoText,NoTextIndex,PrintExponent,(FORMAT(No * DecimalPosition) 
        + '/' + FORMAT(DecimalPosition)));
        //AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 'CENTS '); //TTC_KH
        IF No * DecimalPosition = 0 THEN
            AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 'ZERO')
        ELSE BEGIN
            Ones := No * DecimalPosition;
            Tens := (Ones MOD 100) DIV 10;
            Ones := Ones MOD 10;
            IF Tens >= 2 THEN BEGIN
                AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                TensText[Tens]);
                IF Ones > 0 THEN
                    AddToNoText_USversion(NoText, NoTextIndex, 
                    PrintExponent, OnesText[Ones]);
            END ELSE
                IF (Tens * 10 + Ones0 THEN
                    AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 
                    OnesText[Tens * 10 + Ones]);
        END;
        // TTC_KH End
        //TTC_KH_START
        IF (CurrencyCode = 'MVR'THEN
            AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 'LAARI ONLY')
        ELSE
            AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, 'CENTS ONLY');
        //TTC_KH_EMd
        // IF CurrencyCode <> '' THEN
        //     AddToNoText_USversion(NoText, NoTextIndex, PrintExponent, CurrencyCode);
    end;

    local procedure AddToNoText_USversion(var NoText: array[2of Text
    var NoTextIndex: Integervar PrintExponent: Boolean; AddText: Text[30])
    begin
        PrintExponent := TRUE;

        WHILE STRLEN(NoText[NoTextIndex] + ' ' + AddText> MAXSTRLEN(NoText[1]DO BEGIN
            NoTextIndex := NoTextIndex + 1;
            IF NoTextIndex > ARRAYLEN(NoTextTHEN
                ERROR(Text029, AddText);
        END;

        NoText[NoTextIndex] := DELCHR(NoText[NoTextIndex] + ' ' + AddText, '<');
    end;

    local procedure GetAmtDecimalPosition_USversion()Decimal
    var
        Currency: Record Currency;
        GenJnlLine: Record "Gen. Journal Line";
    begin
        IF GenJnlLine."Currency Code" = '' THEN
            Currency.InitRoundingPrecision
        ELSE BEGIN
            Currency.GET(GenJnlLine."Currency Code");
            Currency.TESTFIELD("Amount Rounding Precision");
        END;
        EXIT(1 / Currency."Amount Rounding Precision");
    end;
    //TTC_KH_AmountInWords_USversion_END
    //TTC_KH_AmountInWords_INversion_START
    procedure InitTextVariable_INversion()
    begin
        OnesText[1] := Text032;
        OnesText[2] := Text033;
        OnesText[3] := Text034;
        OnesText[4] := Text035;
        OnesText[5] := Text036;
        OnesText[6] := Text037;
        OnesText[7] := Text038;
        OnesText[8] := Text039;
        OnesText[9] := Text040;
        OnesText[10] := Text041;
        OnesText[11] := Text042;
        OnesText[12] := Text043;
        OnesText[13] := Text044;
        OnesText[14] := Text045;
        OnesText[15] := Text046;
        OnesText[16] := Text047;
        OnesText[17] := Text048;
        OnesText[18] := Text049;
        OnesText[19] := Text050;

        TensText[1] := '';
        TensText[2] := Text051;
        TensText[3] := Text052;
        TensText[4] := Text053;
        TensText[5] := Text054;
        TensText[6] := Text055;
        TensText[7] := Text056;
        TensText[8] := Text057;
        TensText[9] := Text058;

        ExponentText[1] := '';
        ExponentText[2] := Text059;
        ExponentText[3] := Text1280000;
        ExponentText[4] := Text1280001;
    end;

    procedure FormatNoText_INversion(var NoText: array[2of Text; No: Decimal
    CurrencyCode: Code[10])
    var
        PrintExponent: Boolean;
        Ones: Integer;
        Tens: Integer;
        Hundreds: Integer;
        Exponent: Integer;
        NoTextIndex: Integer;
        Currency: Record Currency;
        TensDec: Integer;
        OnesDec: Integer;
    begin
        CLEAR(NoText);
        NoTextIndex := 1;
        NoText[1] := '****';

        IF No < 1 THEN
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, Text026)
        ELSE
            FOR Exponent := 4 DOWNTO 1 DO BEGIN
                PrintExponent := FALSE;
                IF No > 99999 THEN BEGIN
                    Ones := No DIV (POWER(100, Exponent - 110);
                    Hundreds := 0;
                END ELSE BEGIN
                    Ones := No DIV POWER(1000, Exponent - 1);
                    Hundreds := Ones DIV 100;
                END;
                Tens := (Ones MOD 100) DIV 10;
                Ones := Ones MOD 10;
                IF Hundreds > 0 THEN BEGIN
                    AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                    OnesText[Hundreds]);
                    AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, Text027);
                END;
                IF Tens >= 2 THEN BEGIN
                    AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                    TensText[Tens]);
                    IF Ones > 0 THEN
                        AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                        OnesText[Ones]);
                END ELSE
                    IF (Tens * 10 + Ones0 THEN
                        AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                        OnesText[Tens * 10 + Ones]);
                IF PrintExponent AND (Exponent > 1THEN
                    AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                    ExponentText[Exponent]);
                IF No > 99999 THEN
                    No := No - (Hundreds * 100 + Tens * 10 + Ones
                    POWER(100, Exponent - 110
                ELSE
                    No := No - (Hundreds * 100 + Tens * 10 + Ones
                    POWER(1000, Exponent - 1);
            END;

        IF CurrencyCode <> '' THEN BEGIN
            Currency.GET(CurrencyCode);
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, Currency.Code);
        END ELSE
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, '');

        AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, Text028);
        // AddToNoText(NoText,NoTextIndex,PrintExponent,FORMAT(No * 100) + '/100');

        TensDec := ((No * 100) MOD 100) DIV 10;
        OnesDec := (No * 100) MOD 10;
        IF TensDec >= 2 THEN BEGIN
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, TensText[TensDec]);
            IF OnesDec > 0 THEN
                AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, OnesText[OnesDec]);
        END ELSE
            IF (TensDec * 10 + OnesDec0 THEN
                AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 
                OnesText[TensDec * 10 + OnesDec])
            ELSE
                AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, Text026);
        IF (CurrencyCode = 'MVR'THEN
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 'LAARI ONLY')
        ELSE
            AddToNoText_INversion(NoText, NoTextIndex, PrintExponent, 'CENTS ONLY')
    end;

    local procedure AddToNoText_INversion(var NoText: array[2of Text[80]; 
    var NoTextIndex: Integervar PrintExponent: Boolean; AddText: Text[30])
    begin
        PrintExponent := TRUE;

        WHILE STRLEN(NoText[NoTextIndex] + ' ' + AddText> MAXSTRLEN(NoText[1]DO BEGIN
            NoTextIndex := NoTextIndex + 1;
            IF NoTextIndex > ARRAYLEN(NoTextTHEN
                ERROR(Text029, AddText);
        END;
        NoText[NoTextIndex] := DELCHR(NoText[NoTextIndex] + ' ' + AddText, '<');
    end;

    //TTC_KH_AmountInWords_INversion_END

}

To Print Amount in International no. system we have to use these below functions of check Reports.

(1) InitTextVariable_USversion

(2) FormatNoText_USversion

And To Print Amount in Local No. System say (ones, tens, hundred, thousand, lakh etc), we have to use below mentioned functions of check Reports.

(1) InitTextVariable_INversion

(2) FormatNoText_INversion

Refer below link to know how to print Amount in words using check Report or how to use above functions to Print Amount in Words in Business central / Nav Reports.

https://kunalhuria.blogspot.com/2020/12/amount-in-words-in-navision-business.html?view=sidebar


I hope these articles helps you to print Amount in words in Business Central / Navision Reports.

Comments

Popular posts from this blog

Flow Custom field to G/L Entry and other Posted tables : From Purchase Order to Posted Purchase invoice

Hi Readers, In this blog we will see how we can transfer data from " Purchase Header" to "Purchase Invoice Header" & "G/L Entry" table in Business Central. In this example, will create "Remarks" field on Purchase Header table and after posting, flow it to Purchase Invoice Header & G/L Entry tables: Firsly, create required fields ("Remarks") in below mentioned tables by creating table extensions: Purchase Header (38) Purch. Inv. Header (122) Gen. Journal Line (81)  G/L Entry (17) For the Purch. Inv. Header table, you can just create copy the field from purchase header and paste it in  Purch. Inv. Header  table. If the field ID No. is same for that field for both the tables then you don't have to code i.e, it automatically transfer that field data from Purch. Header to Purch. Inv. Header . Step-(1)   tableextension   50104  "Purchase Header Ext"  extends  "Purchase Header" {      fields   ...

Amount In Words in Navision / Business Central

Hi Guys, In this article, we will see how to display amount in words in Microsoft Dynamics Business Central. Here, I am taking an example of Report object  which is widely used in Navision for converting decimal amount field into words. Procedure :-  Step-1 Declare the following Global Variables :         RepCheck:  Report  "Check";         NoText:  array [ 2 ]  of   Text ;         AmountInWords:  Text ; where, (1) RepCheck is a variable of  Report DataType Named as " Check " which is 1401. (2) NoText is a variable of DataType " Text " with array Dimension value as 2 which is defined as shown above. (3) AmountInWords is a variable of DataType " Text " which will store final result of amount in words. Step-2 Now, add the following code in OnAfterGetRecord() trigger of DataItem containing that decimal field value. So in my cu...

The Txt2Al Conversion Tool: How to Export Dynamics NAV objects (.txt) and converting to AL

Hi folks, In this article, I will show you how you can use Txt2Al conversion tool that is the part of NAV 2018 and Dynamics 365 Business Central On-Premise. Using this Txt2Al conversion tool you can take existing Dynamics NAV objects that have been exported in .txt format and convert them into the new .al format and use these .al format file directly using Visual Studio Code to develop/build extensions for Dynamics 365 Business Central. Converting the NAV objects consists of following 2 steps: 1. Exporting the objects from C/SIDE [Either from Development Environment or using PowerShell Command] 2. Converting the objects to the new syntax. You can find Txt2Al tool in following location if you installed Dynamics 365 Business Central On-Premise on your machine: C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\140\RoleTailored Client \Txt2Al.exe Steps to use the Txt2Al conversion tool:  Reference Step 1:  Compile your Dynamics NAV DB Step 2: ...