13,085,613 members (94,450 online)
alternative version

#### Stats

53.2K views
16 bookmarked
Posted 10 Jun 2004

# Convert Arabic Number to equivalent Arabic text

, 10 Jun 2004
 Rate this:
Convert Arabic number to equivalent Arabic text.

## Introduction

My friend Hassan is a teacher and he is responsible for printing students' certificates where the certificates must contain a student's total degree written in Arabic. So he asked me for a program that accepts Arabic number and returns the equivalent Arabic text.

## Using the code

At the first, Hassan proposed to check the input number directly, so his code looked like this:

```if(num==0) output="Zero";
else if(num==1) output="One";//...and so on.```

My idea is to divide the number to four sections:

```Num4 = (int)Number / 1000;
Num5 = Number % 1000;//Num5=1000s
Num1 = (int)Num5 / 100;
Num0 = Num5%100;//Num0=100s
Num2 = (int)Num0 / 10;//Num2=10s
Num3 = Num0%10;//Num3=1s
```

So, we get count of ones in Num3, tens in Num2, hundreds in Num0 and thousands in Num5, and then we can compare each individual Num with its range:

```Num3 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
Num2 (0, 10, 20, 30, 40, 50, 60, 70, 80, 90),
Num0 (0, 100, 200, 300, 400, 500, 600, 700, 800, 900)
And Num0 (0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000)```

At the end, we get a string which is an equivalent Arabic text, with 40 (`if`) clauses only.

You can use this code in any application like the demo project that comes with this tutorial:

```private void textBox1_TextChanged(object sender, System.EventArgs e)
{
lblNum.Text=NumToArabicString.NtoS(textBox1.Text);
}```

## Points of Interest

You can change Arabic strings to English strings or any language to get the same result.

## Hints

Don't forget to enable Arabic script to your Windows to be able to view the code well.

A list of licenses authors might use can be found here

## Share

Senior Development Manager, with 11 years of experience. Focused on design/developing/delivery B/OSS modules to satisfy customer/business requirements in accordance to TM Forum's TAM/SID framework. Excellent communication and interpersonal skills, flexibility, ability to adjust to new people and situations, strong problem solving skills and willing to work effectively and efficiently. Gained additional leadership skills such as: - High effective mentorship and coaching - Clearly communication and solutions sharing with my team - Decision making

## You may also be interested in...

 First Prev Next
 English to Arabic text for printing in Arabic Aswartha Vamsi4-Nov-13 4:42 Aswartha Vamsi 4-Nov-13 4:42
 Convert Arabic Number to equivalent Arabic text Member 303280631-Jul-11 3:26 Member 3032806 31-Jul-11 3:26
 Re: Convert Arabic Number to equivalent Arabic text kamkho28-Dec-13 23:11 kamkho 28-Dec-13 23:11
 An easier way (IMHO) Harkos14-Jun-04 1:03 Harkos 14-Jun-04 1:03
 I believe there's an easier way to accomplish this task: why don't you convert the number into a string? I think it's easier to work 'int i = 1234567' as 'string s = "1234567"'. My trial is made of two functions like this: ```// Process only a 3-char block (they all work the same) private string Work3Chars(string s) { // Never comes more than 3 chars if(int.Parse(s) == 0) return "zero"; while(s.Length < 3) s = '0' + s; string ret = ""; switch(s[0]) { //case '0': do nothing; case '1': ret = "a hundred"; break; case '2': ret = "two hundred"; break; ... } if(ret == "") ret += ' '; switch(s[1]) { case '0': if(s[0] != '0' && s[2] != '0') ret += "and"; break; case '1': switch(s[2]) { case '0': ret += "ten"; break; case '1': ret += "eleven"; break; case '2': ret += "twelve"; break; ... } return ret.Trim(); case '2': ret += "twenty"; break; ... } switch(s[2]) { //case '0': nothing again; case '1': ret += " one"; break; case '2': ret += " two"; break; ... } return ret.Trim(); }   // This is the callable method public string IntToText(int num) { string n = num.ToString(); while(n.Length % 3 != 0) n = '0' + n; string ret = ""; for(int i = 0; i < n.Length / 3; ++i) { string s = n.Substring(i * 3, 3); if(int.Parse(s) > 0) { ret += Work3Chars(s); switch((n.Length / 3)- i) { //case 0: never happens; //case 1: should be ignored; case 2: ret += " thousand"; break; case 3: ret += " million"; break; ... //add as many levels as desired/possible } if(int.Parse(s) > 1) ret += 's'; ret += ' '; } } return ret.Trim(); }``` I truly believe this should be even smaller when complete. I definitely don't know about performance issues; this is the "first version" or "draft" of the code. There might be some mistakes about the generated text form but it's simple to correct. If anyone find them, please let me know. []'s Harkos --- "Money isn't our god, integrity will free our soul." Cut Throat - Sepultura
 Re: An easier way (IMHO) Taha Zayed14-Jun-04 15:15 Taha Zayed 14-Jun-04 15:15
 some comments (don't read if you don't have arabic fonts :) ) hspc12-Jun-04 0:30 hspc 12-Jun-04 0:30
 Re: some comments (don't read if you don't have arabic fonts :) ) Taha Zayed14-Jun-04 15:18 Taha Zayed 14-Jun-04 15:18
 Last Visit: 31-Dec-99 18:00     Last Update: 16-Aug-17 8:11 Refresh 1