Click here to Skip to main content
Licence 
First Posted 10 Jun 2004
Views 40,616
Bookmarked 17 times

Convert Arabic Number to equivalent Arabic text

By | 10 Jun 2004 | Article
Convert Arabic number to equivalent Arabic text.

Sample Image

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Taha Amin

Team Leader
http://www.linkdev.com/
Egypt Egypt

Member

B/OSS.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionConvert Arabic Number to equivalent Arabic text PinmemberMember 30328063:26 31 Jul '11  
GeneralAn easier way (IMHO) PinmemberHarkos1:03 14 Jun '04  
GeneralRe: An easier way (IMHO) PinmemberTaha Zayed15:15 14 Jun '04  
Generalsome comments (don't read if you don't have arabic fonts :) ) Pinmemberhspc0:30 12 Jun '04  
GeneralRe: some comments (don't read if you don't have arabic fonts :) ) PinmemberTaha Zayed15:18 14 Jun '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.5.120517.1 | Last Updated 11 Jun 2004
Article Copyright 2004 by Taha Amin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid