Click here to Skip to main content
Click here to Skip to main content

Number to Arabic text by 27 digits before point and 27 digits after point

, 6 Jul 2006
Rate this:
Please Sign up or sign in to vote.
Number to Arabic text by 27 digits before point and 27 digits after point
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </head> <body>

using System;

 

namespace Number_to_Text

{

     /// <summary>

     /// Summary description for Class1.

     /// </summary>

     public class Number_to_Arabic_Text

     {

          public Number_to_Arabic_Text()

          {

              //

              // TODO: Add constructor logic here

              //

          }

          private static string GetAla7ad(Int64 Num_Under2)

          {

              string F1;

              switch(Num_Under2)

              {

                   case 1 : F1 = "واحد";

                        break;

                   case 2 : F1 = "أثنان ";

                        break;

                   case 3 : F1 = "ثلاثة";

                        break;

                   case 4 : F1 = "أربعة";

                        break;

                   case 5 : F1 = "خمسة";

                        break;

                   case 6 : F1 = "ستة";

                        break;

                   case 7 : F1 = "سبعة";

                        break;

                   case 8 : F1 = "ثمانية";

                        break;   

                   case 9 : F1 = "تسعة";

                        break;

                   default:  F1 = "صفر";

                        break;

              }

              return F1;

          }

          private static string GetAl3asharat(int Num2)

          {

              string F2;

              switch(Num2)

              {

                   case 1 : F2 = "عشرة";

                        break;

                   case 2 : F2 = "عشرون ";

                        break;

                   case 3 : F2 = "ثلاثون";

                        break;

                   case 4 : F2 = "أربعون";

                        break;

                   case 5 : F2 = "خمسون";

                        break;

                   case 6 : F2 = "ستون";

                        break;

                   case 7 : F2 = "سبعون";

                        break;

                   case 8 : F2 = "ثمانون";

                        break;

                   case 9 : F2 = "تسعون";

                        break;

                   default: F2 = "صفر";

                        break;

              }

 

              return F2;

 

          }

          private static string GetAlmeaat(int Num3)

          {

              string F3;

              switch(Num3)

              {

                   case 1 : F3 = "مائة";

                        break;

                   case 2 : F3 = "مائتان ";

                        break;

                   case 3 : F3 = "ثلاثة مائة";

                        break;

                   case 4 : F3 = "أربعة مائة";

                        break;

                   case 5 : F3 = "خمسة مائة";

                        break;

                   case 6 : F3 = "ستة مائة";

                        break;

                   case 7 : F3 = "سبعة مائة";

                        break;

                   case 8 : F3 = "ثمان مائة";

                        break;

                   case 9 : F3 = "تسعة مائة";

                        break;

                   default: F3 = "صفر";

                        break;

              }

              return F3;

          }

          private static string GetAloloof(int Num4)

          {

              string F4;

              switch (Num4)

              {

                   case 1:F4 = "ألف";

                        break;

                   case 2:F4 = "ألفان";

                        break;

                   case 3:F4 = "ثلاثةألاف";

                        break;

                   case 4:F4 = "أربعةألاف";

                        break;

                   case 5:F4 = "خمسةألاف";

                        break;

                   case 6:F4 = "ستةألاف";

                        break;

                   case 7:F4 = "سبعةألاف";

                        break;

                   case 8:F4 = "ثمانيةألاف";

                        break;

                   case 9:F4 = "تسعةألاف";

                        break;

                   default:F4 = "صفر";

                        break;

              }

         

              return F4;

          }

          private static string Get3Digits(string Num)

          {

              string ReturnValue;

 

              string F1, F2, F3;

              int Num_Under3, Num3, Num2, Num_Under2;

 

              F1 = "";

              F2 = "";

              F3 = "";

              if(Num.ToString() == "")

              {

                   Num = "0";

              }   

              int number = int.Parse(Num.ToString());

              if (number >= 0)

              {

                   Num3 = number  / 100;

                   Num_Under3 = number %100;

                   Num2 = (int)Num_Under3 / 10;

                   Num_Under2 = Num_Under3%10;

 

                   // Get Ala7ad

                   F1 = GetAla7ad(Num_Under2);

                   // Get Al3asharat

                   F2 = GetAl3asharat(Num2);

                   if (Num2 != 0)

                   {

                        if ((Num2 == 1) && (Num_Under2 != 0))

                        {

                             F1 = F1 + F2;

                        }

                        else

                        {

                             if ((Num_Under2 !=0)&&( Num2 != 0))

                             {

                                  F1 = F1 + " و " + F2;

                             }

                             else if(Num2!=0)

                             {

                                  F1 = F2;

                             }

                        }

                   }

                   // Get Almeaat

                   F3 = GetAlmeaat(Num3);

                   if ((Num3 > 0)&&( F1 !="صفر"))

                   {

                        F1 = F3 + " و " + F1;

                   }

                   if((Num3 != 0)&&(Num2 == 0)&&(Num_Under2 == 0))

                   {

                        F1 = F3;

                   }

              }

              ReturnValue = F1;

              return ReturnValue;

          }

          private static string Get4Digits(string Num)

          {

              string ReturnValue;

 

              string F1, F2, F3, F4;

              int Num_Under4, Num4,Num_Under3, Num3, Num2, Num_Under2;

 

              F1 = "";

              F2 = "";

              F3 = "";

              F4 = "";

              if(Num.ToString() == "")

              {

                   Num = "0";

              }   

              int number = int.Parse(Num.ToString());

              if (number >= 0)

              {

                   Num4 = number  / 1000;

                   Num_Under4 = number %1000;

                   Num3 = Num_Under4  / 100;

                   Num_Under3 = number %100;

                   Num2 = (int)Num_Under3 / 10;

                   Num_Under2 = Num_Under3%10;

 

                   // Get Ala7ad

                   F1 = GetAla7ad(Num_Under2);

                   // Get Al3asharat

                   F2 = GetAl3asharat(Num2);

                   if (Num2 != 0)

                   {

                        if ((Num2 == 1) && (Num_Under2 != 0))

                        {

                             F1 = F1 + F2;

                        }

                        else

                        {

                             if ((Num_Under2 !=0)&&( Num2 != 0))

                             {

                                  F1 = F1 + " و " + F2;

                             }

                             else if(Num2!=0)

                             {

                                  F1 = F2;

                             }

                        }

                   }

                   // Get Almeaat

                   F3 = GetAlmeaat(Num3);

                   if ((Num3 > 0)&&( F1 !="صفر"))

                   {

                        F1 = F3 + " و " + F1;

                   }

                   if((Num3 != 0)&&(Num2 == 0)&&(Num_Under2 == 0))

                   {

                        F1 = F3;

                   }

                   // Get Aloloof

                   if(Num4 > 0)

                   {

                        F4 = GetAloloof(Num4);

                        if(F1 != "صفر")

                        {

                             F1 = F4 + " و " + F1;

                        }

                        else

                        {

                             F1 = F4;

                        }

                   }

              }

              ReturnValue = F1;

              return ReturnValue;

          }

 

          private static void Cal3Digits(string strType,ref string strNnumber,ref string ReturnValue)

          {

              string Value;

              if(strNnumber.Length > 0)

              {

                   if(strNnumber.Length < 3)

                   {

                        strNnumber = "000" + strNnumber;

                        strNnumber = strNnumber.Substring(strNnumber.Length-3,3);

                   }

                   Value = Get3Digits(strNnumber.Substring(strNnumber.Length-3,3));

                   if(Value != "صفر")

                   {

                        Value = Value + strType;

                   }

                   else

                   {

                        Value = "";

                   }

                   if(ReturnValue != "صفر")

                   {

                        if(Value != "")

                        {

                             if(ReturnValue != "")

                             {

                                  ReturnValue = Value + " و " +  ReturnValue;

                             }

                             else

                             {

                                  ReturnValue = Value;

                             }

                        }

                   }

                   else

                   {

                        ReturnValue = Value;

                   }

                   strNnumber = strNnumber.Substring(0,strNnumber.Length-3);

              }

 

          }

          private static string Convert(string strNnumber)

          {

              string ReturnValue,strThousand,strMillion,strMilyar,strBillion

                   ,strThousandBillion,strMillionBillion,strMilyarBillion,strBillionBillion;

              strThousand = " ألف ";

              strMillion = " مليون ";

              strMilyar = " مليار ";

              strBillion = " بليون ";

              strThousandBillion = " ألف بليون ";

              strMillionBillion = " مليون بليون ";

               strMilyarBillion = " مليار بليون ";

              strBillionBillion = " بليون بليون ";

 

              ReturnValue = "";

             

              if(strNnumber.ToString() == "")

              {

                   strNnumber = "0";

              }

 

              if(strNnumber.Length < 3)

              {

                   strNnumber = "000" + strNnumber;

                   strNnumber = strNnumber.Substring(strNnumber.Length-3,3);

              }

              if(strNnumber.Length == 4)

              {

                   ReturnValue = Get4Digits(strNnumber);

              }

              else

              {

                   ReturnValue = Get3Digits(strNnumber.Substring(strNnumber.Length-3,3));

                   strNnumber = strNnumber.Substring(0,strNnumber.Length-3);

 

                   Cal3Digits(strThousand,ref strNnumber,ref ReturnValue);                  

                   Cal3Digits(strMillion,ref strNnumber,ref ReturnValue);                  

                   Cal3Digits(strMilyar,ref strNnumber,ref ReturnValue);                  

                   Cal3Digits(strBillion,ref strNnumber,ref ReturnValue);                  

                   Cal3Digits(strThousandBillion,ref strNnumber,ref ReturnValue);               

                   Cal3Digits(strMillionBillion,ref strNnumber,ref ReturnValue);               

                   Cal3Digits(strMilyarBillion,ref strNnumber,ref ReturnValue);               

                   Cal3Digits(strBillionBillion,ref strNnumber,ref ReturnValue);               

              }

              return ReturnValue;

          }

 

          public static string NtoS(string strNnumber)

          {

              double Number;

              Int64 BeforePoint,AfterPoint;

              string ReturnValue,strBeforePoint;

              int intIndex;

              ReturnValue = "";

              try

              {

                   Number = double.Parse(strNnumber);

                   BeforePoint = (Int64)Number;

                   strBeforePoint = BeforePoint.ToString();

                   intIndex = strNnumber.Length - strBeforePoint.Length;

                   if(strNnumber.Length > strBeforePoint.Length)

                   {

                        AfterPoint = Int64.Parse(strNnumber.Substring(strNnumber.Length-intIndex+1,intIndex-1));

                   }

                   else

                   {

                        AfterPoint = 0;

                   }

                   if(BeforePoint > 0)

                   {

                        ReturnValue = Convert(BeforePoint.ToString());

                   }

                   if(AfterPoint != 0)

                   {

                        if(ReturnValue != "")

                        {

                             ReturnValue = ReturnValue + " - " + " و " + Convert(AfterPoint.ToString()) + " من " + Convert(((int)(Math.Pow(10,intIndex-1))).ToString()) ;

                        }

                        else

                        {

                             ReturnValue = Convert(AfterPoint.ToString()) + " من " + Convert(((int)(Math.Pow(10,intIndex-1))).ToString()) ;

                        }

                   }

              }

              catch(Exception)

              {

                   strNnumber = "0";

                   ReturnValue = Convert(strNnumber);

              }

              return ReturnValue;

          }

 

     }

}

 

</body> </html>

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

Share

About the Author

adel.adam
Web Developer
Egypt Egypt
No Biography provided

Comments and Discussions

 
QuestionThank you Pinmemberomarabbasaj9-Dec-13 22:44 
Questionported to ruby Pinmemberabdullah.bakhach7-Jun-13 22:54 
GeneralMy vote of 5 PinmemberMustafa Gamal10-Oct-12 5:06 
Great effort Adel Well done
Questionhello Adel PinmemberEdward Topalian12-Sep-08 2:56 
AnswerRe: hello Adel Pinmemberadel.adam12-Sep-08 9:38 
GeneralRe: hello Adel PinmemberEdward Topalian12-Sep-08 23:45 
GeneralGood work... PinmemberSanalNambiar27-Sep-07 0:34 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 6 Jul 2006
Article Copyright 2006 by adel.adam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid