web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Convert Number to Words in Business Central

(1) ShareShare
ReportReport
Posted on by 259
Hi All,
I've written an action to convert a number to words using a codeunit, but I'm encountering an /Index Out of Bounds/ error. I am not sure why this issue is occurring and would greatly appreciate any assistance or solutions you can provide.
For example, 5000 -> 5 thousand.
 
 
page 50323 CustomerInfo
{
    ApplicationArea = All;
    Caption = 'CustomerInfo';
    PageType = List;
    SourceTable = Customer;
    UsageCategory = Lists;
    //InsertAllowed = true;
    //Permissions = tabledata Customer = R;
    InsertAllowed = true;
    DeleteAllowed = true;
    ModifyAllowed = true;
 
   
 
    actions
    {
        area(Processing)
        {
            group(Home)
            {
                action(/Get Number to words/)
                {
                    trigger OnAction()
                    var
                        myInt: Integer;
                        Words: Text;
                    begin
                        myInt := 45;
                        Words := ConvertNumberToWords(myInt);
                        MESSAGE('Number in Words: %1', Words);
                    end;
 
                }
            }
        }
    }
 
    local procedure AmountToWords(Amount: Integer): Text
    var
        Word: Text;
    begin
        Word := FormatAmountInWords(Amount);
        exit(Word);
    end;
 
    local procedure FormatAmountInWords(Amount: Integer): Text
    var
        WholePart: Integer;
        FractionPart: Integer;
        Words: Text;
    begin
        WholePart := Amount;
        //FractionPart := Round((Amount - WholePart) * 100);
 
        Words := ConvertNumberToWords(WholePart) + ' Rupees';
        // if FractionPart > 0 then
        //     Words := Words + ' and ' + ConvertNumberToWords(FractionPart) + ' Paise';
 
        exit(Words);
    end;
 
    local procedure ConvertNumberToWords(Number: Integer): Text
    var
        Units: array[19] of Text[10];
        Tens: array[10] of Text[10];
        Hundreds: array[5] of Text[10];
        Result: Text;
        HValue: Integer;
        TValue: Integer;
    begin
       
        Units[0] := 'Zero';
        Units[1] := 'One';
        Units[2] := 'Two';
        Units[3] := 'Three';
        Units[4] := 'Four';
        Units[5] := 'Five';
        Units[6] := 'Six';
        Units[7] := 'Seven';
        Units[8] := 'Eight';
        Units[9] := 'Nine';
        Units[10] := 'Ten';
        Units[11] := 'Eleven';
        Units[12] := 'Twelve';
        Units[13] := 'Thirteen';
        Units[14] := 'Fourteen';
        Units[15] := 'Fifteen';
        Units[16] := 'Sixteen';
        Units[17] := 'Seventeen';
        Units[18] := 'Eighteen';
        Units[19] := 'Nineteen';
 
        Tens[2] := 'Twenty';
        Tens[3] := 'Thirty';
        Tens[4] := 'Forty';
        Tens[5] := 'Fifty';
        Tens[6] := 'Sixty';
        Tens[7] := 'Seventy';
        Tens[8] := 'Eighty';
        Tens[9] := 'Ninety';
 
        if Number < 20 then
            Result := Units[Number]
        else if (Number < 100) and (Number > 19) then
            Result := Tens[Number DIV 10] + ' ' + Units[Number MOD 10]
        else if (Number > 100) and (Number < 999) then
            HValue := Number MOD 100;
            Result := Units[Number DIV 100] + 'Hundred' + ConvertNumberToWords(HValue);
        if (Number > 999) and (Number < 9999) then
            TValue := Number MOD 1000;
            HValue := HValue MOD 100;
            Result := Units[Number DIV 1000] + 'Thousand' + ConvertNumberToWords(TValue) + ConvertNumberToWords(HValue);
 
        exit(Result);
 
    end;
 
 
}
I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    26,091 Most Valuable Professional on at
  • Suggested answer
    Saurav.Dhyani Profile Picture
    14,419 User Group Leader on at
    Hi,
     
    Don't create custom code for it.
     
    Refer Report 1401 and check how Microsoft is using FormatNoText method to convert amount in words.
     
    The function actual is placed in report 10400 "Check Translation Management"
     
    Regards,
    Saurav Dhyani
  • Suggested answer
    YUN ZHU Profile Picture
    99,974 Super User 2026 Season 1 on at
    Hi, you can also try the standard method below.
    report 1401 Check
     
    Thanks
    ZHU

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,024 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,145 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 705 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans