Convert currency/Number in to words


In electronic based business system like shop billing or any other transactions required to convert Digit to equivalent words for reliability and clarity. here is C# Class with static Num2Word converter

The following code is the C# conversion of VB code from the post in code
Mohammad Ajmal Yazdani replied to Sangeetha Krishnamurthi through http://www.eggheadcafe.com/community/aspnet/2/10013586/re-get-the-code.aspx

<%

 
class BCConverter
{
static string SINGLES = "one,two,three,four,five,"
+"six,seven,eight,nine";
static string DECADES = "ten,eleven,twelve,thirteen,fourteen,"
+"fifteen,sixteen,seventeen,eighteen,nineteen";
static string DECTYS = "twenty,thirty,forty,fifty,"
+"sixty,seventy,eighty,ninety";
static string TIONS = ",thousand,million,billion";
public static string Num2Words(int iNum)
{
int i = iNum;
bool b = false;
string s="";
if (i < 0) { b = true; i = i * -1; }
if (i == 0)
{
s = "zero";
}
else if (i <= 2147483647)
{
string[] a = TIONS.Split(',');
for (int j = 0; j <= 3; j++)
{
int iii = i % 1000;
i = i / 1000;
if (iii > 0) s = nnn2words(iii) + " " + a[j] + " " + s;
}
}
else
{
s = "out of range value";
}
if (b) s = "negative " + s;
return s.Trim();
}

private static string nnn2words(int iNum)
{
string[] a = SINGLES.Split(',');
string s="";
int i = iNum % 10;
if (i > 0) s = a[i - 1];
int ii = Convert.ToInt32(iNum % 100) / 10;
if (ii == 1)
{
s = DECADES.Split(',')[i];
}
else if (((ii > 1) & (ii < 10)))
{
s = DECTYS.Split(',')[ii - 2] + " " + s;
}
i = (iNum / 100) % 10;
if (i > 0) s = a[i - 1] + " hundred " + s;
return s;
}
}


Reference: http://www.eggheadcafe.com/community/aspnet/2/10013586/re-get-the-code.aspx


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: