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 269
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;
 
 
}
  • Suggested answer
    Gerardo Rentería García Profile Picture
    27,623 Super User 2026 Season 2 on at
  • Suggested answer
    Saurav.Dhyani Profile Picture
    14,481 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
    103,660 Super User 2026 Season 2 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 774 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 569 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 296 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans