Click here to Skip to main content
13,593,097 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 18 May 2010
Licenced CPOL

Convert Arabic Numbers or Digits to text

, 18 May 2010
Rate this:
Please Sign up or sign in to vote.
Algorithm to convert Arabic Numbers to Arabic Text using C#


Many Day-to-Day business applications need to have the ability to convert numbers into words. In commercial, accounting or even auditing applications it is really a nice to have feature.


Arabic numbers writing numbers is more complicated than English. In Arabic we have to read the hundreds first then ones after that tens. Unlike English which is more easier to read and it is one way.

There is also another way in Arabic to read numbers to begin from ones then tens then hundreds but this is not a very well-known method.

The code used here is considering the daily needs of accounting programs. Thus, it uses modern Arabic accounting language which may not be 100% compatible with Arabic grammar rules.

More efforts is needed if we are going to consider the gender of the count, the two cases and the morphology analysis which is out of the scope of the current code snippet.

Using the Code

The main entry of the Class NumberingFormatter is the method getResultEnhanced().

This method is taking care of the Arabic number string entered and analyze whether the string is millions or hundreds or thousands. Based on these rules, the string is submitted to different methods depends on the nature of the String.

public string getResultEnhanced()
            String result = "";
            if (Number.Length % 3 == 1)
                Number = "00" + Number;
            else if (Number.Length % 3 == 2)
                Number = "0" + Number;
            if (Number.Length == 3)
                result = getThreeNumberCase(Number);
            else if (Number.Length == 6)
                result = getSixNumberCase(Number);
            else if (Number.Length == 9)
                result = getNineNumberCase(Number);
            result = result.Replace("  ", " ");
            result = result.Replace("   ", " ");
            result = result.Replace(" و ريال", " ريال ");
            return result;

Other than this there is only a structure of methods to deal with words and numbering.

Of course, the parts of the numbers are stored in static variable like tens and hundreds, and then composed up to build the final text.

Please notice that the algorithm doesn't have any defensive approach against the wrong input like letters or 000005 because of simplicity and separation of concerns. It is assumed that the front-end consumer or the controller will do the input sanitation check.

Points of Interest

There was a big discussion about million number is it Arabic or not. But the clear fact is that Million مليون doesn't have Arabic root. The algorithm dealt with millions in a different way than thousands or hundreds.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Saudi Arabia Saudi Arabia
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionQuestion Pin
Member 1248419120-Oct-16 21:10
memberMember 1248419120-Oct-16 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180618.1 | Last Updated 18 May 2010
Article Copyright 2010 by xprog
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid