12,953,937 members (42,679 online)
Tip/Trick
alternative version

#### Stats

38.4K views
6 bookmarked
Posted 7 Nov 2012

# Convert Arabic Number To Alphabet (التفقيط) تحويل الأرقام إلى حروف

, 11 Nov 2012 CPOL
 Rate this:
تفقيط الأرقام العربيه

## Introduction

Convert any number consisting of digits (from one digit to six digits) into Arabic alphabets. Also it handles "."

## Background

The basic idea is to divide the number into two separeted parts if it contains "." and take every part as a number  then convert this number to alphabet by dividing it to digits.

## Using the code

You just need to use the class called ConvertNumbersToArabicAlphabet and you should pass a number consisting of six digits or less to its constructor.

//
//Use This class directly if you want to convert numbers to Alphabet but feel free to modify any mehod
//

* I think it will be better if you download the version of this class 'attached'
because it has an arabic charcter which will not be displayed right if I write it here
class ConvertNumbersToArabicAlphabet
{
string NumberAr;
public  ConvertNumbersToArabicAlphabet(string Number)
{
NumberAr=  ConvertNumberToAlpha(Number);
}
private string ConvertNumberToAlpha(string Number)
{
if (Number.Contains('.'))
{
if (Number.Split('.')[0].ToCharArray().Length > 6)
{
return "No Number";
}
else
{
switch (Number.Split('.')[0].ToCharArray().Length)
{
case 1: return convertOneDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
case 2: return convertTwoDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
case 3: return convertThreeDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
case 4: return convertFourDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
case 5: return convertFiveDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
case 6: return convertSixDigits(Number.ToString()) + " جنيها " + " و " + convertTwoDigits(Number.Split('.')[1]) + " قرشا ";
default: return "";
}
}
}
else
{
if (Number.ToCharArray().Length > 6)
{
return "No Number";
}
else
{
switch (Number.ToCharArray().Length)
{
case 1: return convertOneDigits(Number.ToString())    + " جنيها ";
case 2: return convertTwoDigits(Number.ToString()) + " جنيها ";
case 3: return convertThreeDigits(Number.ToString()) + " جنيها ";
case 4: return convertFourDigits(Number.ToString()) + " جنيها " ;
case 5: return convertFiveDigits(Number.ToString()) + " جنيها " ;
case 6: return convertSixDigits(Number.ToString()) + " جنيها " ;
default: return "";
}

}
}
}
private string convertTwoDigits(string TwoDigits)
{
string returnAlpha = "00";
if (TwoDigits.ToCharArray()[0] == '0' && TwoDigits.ToCharArray()[1] != '0')
{
return convertOneDigits(TwoDigits.ToCharArray()[1].ToString());
}
else
{
switch (int.Parse(TwoDigits.ToCharArray()[0].ToString()))
{
case 1:
{
if (int.Parse(TwoDigits.ToCharArray()[1].ToString()) == 1)
{
return "إحدى عشر";
}
else if (int.Parse(TwoDigits.ToCharArray()[1].ToString()) == 2)
{
return "إثنى عشر";
}
else
{
returnAlpha = "عشر";
return convertOneDigits(TwoDigits.ToCharArray()[1].ToString()) + " " + returnAlpha;
}
}
case 2: returnAlpha = "عشرون"; break;
case 3: returnAlpha = "ثلاثون"; break;
case 4: returnAlpha = "أريعون"; break;
case 5: returnAlpha = "خمسون"; break;
case 6: returnAlpha = "ستون"; break;
case 7: returnAlpha = "سبعون"; break;
case 8: returnAlpha = "ثمانون"; break;
case 9: returnAlpha = "تسعون"; break;
default: returnAlpha = ""; break;
}
}
if (convertOneDigits(TwoDigits.ToCharArray()[1].ToString()).Length == 0)
{ return returnAlpha; }
else
{
return convertOneDigits(TwoDigits.ToCharArray()[1].ToString()) + " و " + returnAlpha;
}
}
private string convertOneDigits(string OneDigits)
{
switch (int.Parse(OneDigits))
{
case 1: return "واحد";
case 2: return "إثنان";
case 3: return "ثلاثه";
case 4: return "أربعه";
case 5: return "خمسه";
case 6: return "سته";
case 7: return "سبعه";
case 8: return "ثمانيه";
case 9: return "تسعه";
default: return "";
}
}
private string convertThreeDigits(string ThreeDigits)
{
switch (int.Parse(ThreeDigits.ToCharArray()[0].ToString()))
{
case 1:
{
if (int.Parse(ThreeDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(ThreeDigits.ToCharArray()[2].ToString()) == 0)
{
return "مائه";
}
return "مائه" + " و " + convertOneDigits(ThreeDigits.ToCharArray()[2].ToString());
}
else
{
return "مائه" + " و " + convertTwoDigits(ThreeDigits.Substring(1, 2));
}
}
case 2:
{
if (int.Parse(ThreeDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(ThreeDigits.ToCharArray()[2].ToString()) == 0)
{
return "مائتين";
}
return "مائتين" + " و " + convertOneDigits(ThreeDigits.ToCharArray()[2].ToString());
}
else
{
return "مائتين" + " و " + convertTwoDigits(ThreeDigits.Substring(1, 2));
}
}
case 3:
{
if (int.Parse(ThreeDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(ThreeDigits.ToCharArray()[2].ToString()) == 0)
{
return convertOneDigits(ThreeDigits.ToCharArray()[0].ToString()).Split('ه')[0] + "مائه";
}
return convertOneDigits(ThreeDigits.ToCharArray()[0].ToString()).Split('ه')[0] + "مائه" + " و " + convertOneDigits(ThreeDigits.ToCharArray()[2].ToString());
}
else
{
return convertOneDigits(ThreeDigits.ToCharArray()[0].ToString()).Split('ه')[0] + "مائه" + " و " + convertTwoDigits(ThreeDigits.Substring(1, 2));
}
}
case 4:
{
goto case 3;
}
case 5:
{
goto case 3;
}
case 6:
{
goto case 3;
}
case 7:
{
goto case 3;
}
case 8:
{
goto case 3;
}
case 9:
{
goto case 3;
}
case 0:
{
if (ThreeDigits.ToCharArray()[1] == '0')
{
if (ThreeDigits.ToCharArray()[2] == '0')
{
return "";
}
else
{
return convertOneDigits(ThreeDigits.ToCharArray()[2].ToString());
}
}
else
{
return convertTwoDigits(ThreeDigits.Substring(1, 2));
}
}
default: return "";
}
}
private string convertFourDigits(string FourDigits)
{
switch (int.Parse(FourDigits.ToCharArray()[0].ToString()))
{
case 1:
{
if (int.Parse(FourDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[2].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[3].ToString()) == 0)
return "ألف";
else
{
return "ألف" + " و " + convertOneDigits(FourDigits.ToCharArray()[3].ToString());
}
}
return "ألف" + " و " + convertTwoDigits(FourDigits.Substring(2, 2));
}
else
{
return "ألف" + " و " + convertThreeDigits(FourDigits.Substring(1, 3));
}
}
case 2:
{
if (int.Parse(FourDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[2].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[3].ToString()) == 0)
return "ألفين";
else
{
return "ألفين" + " و " + convertOneDigits(FourDigits.ToCharArray()[3].ToString());
}
}
return "ألفين" + " و " + convertTwoDigits(FourDigits.Substring(2, 2));
}
else
{
return "ألفين" + " و " + convertThreeDigits(FourDigits.Substring(1, 3));
}
}
case 3:
{
if (int.Parse(FourDigits.ToCharArray()[1].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[2].ToString()) == 0)
{
if (int.Parse(FourDigits.ToCharArray()[3].ToString()) == 0)
return convertOneDigits(FourDigits.ToCharArray()[0].ToString()) + " ألاف";
else
{
return convertOneDigits(FourDigits.ToCharArray()[0].ToString()) + " ألاف" + " و " + convertOneDigits(FourDigits.ToCharArray()[3].ToString());
}
}
return convertOneDigits(FourDigits.ToCharArray()[0].ToString()) + " ألاف" + " و " + convertTwoDigits(FourDigits.Substring(2, 2));
}
else
{
return convertOneDigits(FourDigits.ToCharArray()[0].ToString()) + " ألاف" + " و " + convertThreeDigits(FourDigits.Substring(1, 3));
}
}
case 4:
{
goto case 3;
}
case 5:
{
goto case 3;
}
case 6:
{
goto case 3;
}
case 7:
{
goto case 3;
}
case 8:
{
goto case 3;
}
case 9:
{
goto case 3;
}
default: return "";
}
}
private string convertFiveDigits(string FiveDigits)
{
if (convertThreeDigits(FiveDigits.Substring(2, 3)).Length == 0)
{
return convertTwoDigits(FiveDigits.Substring(0, 2)) + " ألف ";
}
else
{
return convertTwoDigits(FiveDigits.Substring(0, 2)) + " ألفا " + " و " + convertThreeDigits(FiveDigits.Substring(2, 3));
}
}
private string convertSixDigits(string SixDigits)
{
if (convertThreeDigits(SixDigits.Substring(2, 3)).Length == 0)
{
return convertThreeDigits(SixDigits.Substring(0, 3)) + " ألف ";
}
else
{
return convertThreeDigits(SixDigits.Substring(0, 3)) + " ألفا " + " و " + convertThreeDigits(SixDigits.Substring(3, 3));
}
}

public string GetNumberAr()
{

return NumberAr;
}

}

## Points of Interest

I think it is a good practise using switch and the divide and conqure technique.

## History

• 07 November 2012: Initial version.
• 08 November 2012 : Updated
• 11 November 2012 : Updated

## Share

 Egypt
No Biography provided

## You may also be interested in...

 Pro

 First Prev Next
 مشكلة مع الكسور Golden Basim18-Dec-15 3:01 Golden Basim 18-Dec-15 3:01
 about converting Arabic numbers Member 1204938331-Oct-15 4:01 Member 12049383 31-Oct-15 4:01
 Re: about converting Arabic numbers ahmed_alashrafy26-Apr-16 1:12 ahmed_alashrafy 26-Apr-16 1:12
 My vote of 4 ibrahim_ragab20-May-13 14:09 ibrahim_ragab 20-May-13 14:09
 My vote of 5 Ahmed Ibrahim Assaf10-Dec-12 21:31 Ahmed Ibrahim Assaf 10-Dec-12 21:31
 bug sastocker9-Nov-12 4:15 sastocker 9-Nov-12 4:15
 Re: bug ahmed_alashrafy11-Nov-12 2:39 ahmed_alashrafy 11-Nov-12 2:39
 My vote of 3 moha77-Nov-12 22:12 moha7 7-Nov-12 22:12
 Re: My vote of 3 ahmed_alashrafy7-Nov-12 23:33 ahmed_alashrafy 7-Nov-12 23:33
 Re: My vote of 3 ahmed_alashrafy7-Nov-12 23:35 ahmed_alashrafy 7-Nov-12 23:35
 Re: My vote of 3 ahmed_alashrafy8-Nov-12 6:14 ahmed_alashrafy 8-Nov-12 6:14
 Re: My vote of 3 ahmed_alashrafy8-Nov-12 9:13 ahmed_alashrafy 8-Nov-12 9:13
 Re: My vote of 3 Member 114154917-Feb-15 23:44 Member 11415491 7-Feb-15 23:44
 Last Visit: 31-Dec-99 18:00     Last Update: 28-May-17 3:00 Refresh 1