"Scott Coonce" <sd******@gmail .HEY_YOU.com> wrote in message
news:Ov******** ******@TK2MSFTN GP12.phx.gbl...
... and no, I don't know of anything that'll do that. Sorry.
Below is an extremely crude piece of code which will do the job. Before you
all jump down my throat at how inefficient and inelegant it is, you're
absolutely right! It's not intended to be an exercise in concise coding,
rather an example that the OP can use to modify as required...
private string NumberToWords(s tring pstrNumber)
{
Hashtable htblNumbers = new Hashtable();
htblNumbers.Add (0, "zero");
htblNumbers.Add (1, "one");
htblNumbers.Add (2, "two");
htblNumbers.Add (3, "three");
htblNumbers.Add (4, "four");
htblNumbers.Add (5, "five");
htblNumbers.Add (6, "six");
htblNumbers.Add (7, "seven");
htblNumbers.Add (8, "eight");
htblNumbers.Add (9, "nine");
htblNumbers.Add (10, "ten");
htblNumbers.Add (11, "eleven");
htblNumbers.Add (12, "twelve");
htblNumbers.Add (13, "thirteen") ;
htblNumbers.Add (14, "fourteen") ;
htblNumbers.Add (15, "fifteen");
htblNumbers.Add (16, "sixteen");
htblNumbers.Add (17, "seventeen" );
htblNumbers.Add (18, "eighteen") ;
htblNumbers.Add (19, "nineteen") ;
htblNumbers.Add (20, "twenty");
htblNumbers.Add (30, "thirty");
htblNumbers.Add (40, "forty");
htblNumbers.Add (50, "fifty");
htblNumbers.Add (60, "sixty");
htblNumbers.Add (70, "seventy");
htblNumbers.Add (80, "eighty");
htblNumbers.Add (90, "ninety");
string strOutput = "";
string[] astrNumber = pstrNumber.Spli t('.');
if(astrNumber[0].Length > 15)
{
return "Number is too long to convert";
}
else
{
astrNumber[0] = astrNumber[0].PadLeft(15, '0');
}
// trillions ------------------------------------------
if(Convert.ToIn t32(astrNumber[0].Substring(0, 3)) > 0)
{
if(astrNumber[0].Substring(0, 1) != "1")
{
strOutput += htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(0,
1))] + " hundred";
}
if(Convert.ToIn t32(astrNumber[0].Substring(1, 2)) > 0 &&
Convert.ToInt32 (astrNumber[0].Substring(1, 2)) < 20)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(1, 2))];
}
if(Convert.ToIn t32(astrNumber[0].Substring(1, 2)) > 19)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(1, 1) + "0")];
if(Convert.ToIn t32(astrNumber[0].Substring(2, 1)) > 0)
{
strOutput += "-" +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(2, 1))];
}
}
strOutput += " trillion ";
}
// billions ------------------------------------------
if(Convert.ToIn t32(astrNumber[0].Substring(3, 3)) > 0)
{
if(astrNumber[0].Substring(3, 1) != "1")
{
strOutput += htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(3,
1))] + " hundred";
}
if(Convert.ToIn t32(astrNumber[0].Substring(4, 2)) > 0 &&
Convert.ToInt32 (astrNumber[0].Substring(4, 2)) < 20)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(4, 2))];
}
if(Convert.ToIn t32(astrNumber[0].Substring(4, 2)) > 19)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(4, 1) + "0")];
if(Convert.ToIn t32(astrNumber[0].Substring(5, 1)) > 0)
{
strOutput += "-" +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(5, 1))];
}
}
strOutput += " billion ";
}
// millions ------------------------------------------
if(Convert.ToIn t32(astrNumber[0].Substring(6, 3)) > 0)
{
if(astrNumber[0].Substring(6, 1) != "1")
{
strOutput += htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(6,
1))] + " hundred";
}
if(Convert.ToIn t32(astrNumber[0].Substring(7, 2)) > 0 &&
Convert.ToInt32 (astrNumber[0].Substring(7, 2)) < 20)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(7, 2))];
}
if(Convert.ToIn t32(astrNumber[0].Substring(7, 2)) > 19)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(7, 1) + "0")];
if(Convert.ToIn t32(astrNumber[0].Substring(8, 1)) > 0)
{
strOutput += "-" +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(8, 1))];
}
}
strOutput += " million ";
}
// thousands ------------------------------------------
if(Convert.ToIn t32(astrNumber[0].Substring(9, 3)) > 0)
{
if(astrNumber[0].Substring(9, 1) != "1")
{
strOutput += htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(9,
1))] + " hundred";
}
if(Convert.ToIn t32(astrNumber[0].Substring(10, 2)) > 0 &&
Convert.ToInt32 (astrNumber[0].Substring(10, 2)) < 20)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(10, 2))];
}
if(Convert.ToIn t32(astrNumber[0].Substring(10, 2)) > 19)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(10, 1) + "0")];
if(Convert.ToIn t32(astrNumber[0].Substring(11, 1)) > 0)
{
strOutput += "-" +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(11, 1))];
}
}
strOutput += " thousand ";
}
// hundreds, tens and ones ---------------------------------------------
if(Convert.ToIn t32(astrNumber[0].Substring(12, 3)) > 0)
{
if(astrNumber[0].Substring(12, 1) != "1")
{
strOutput += htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(12,
1))] + " hundred";
}
if(Convert.ToIn t32(astrNumber[0].Substring(13, 2)) > 0 &&
Convert.ToInt32 (astrNumber[0].Substring(13, 2)) < 20)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(13, 2))];
}
if(Convert.ToIn t32(astrNumber[0].Substring(13, 2)) > 19)
{
strOutput += " and " +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(13, 1) + "0")];
if(Convert.ToIn t32(astrNumber[0].Substring(14, 1)) > 0)
{
strOutput += "-" +
htblNumbers[Convert.ToInt32 (astrNumber[0].Substring(14, 1))];
}
}
}
// decimal places ------------------------------------------------------
if(astrNumber.L ength == 2)
{
strOutput += " point";
foreach (char strDigit in astrNumber[1].ToCharArray())
{
strOutput += " " + htblNumbers[Convert.ToInt32 (strDigit.ToStr ing())];
}
}
return strOutput.Repla ce(" ", " ");
}