public string ConvertToAmountInText(double numberToConvert, bool BlankIfZero, bool ConvertDecimalPart)
{
long Number = (long)numberToConvert;
string strNumberInText = "";
if (Number == 0)
return (BlankIfZero ? "" : "Zero");
else if (Number >= 1 && Number <= 19)
{
string[] numbers = {"One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"};
strNumberInText = numbers[Number - 1];
}
else if (Number >= 20 && Number <= 99)
{
string[] numbers = { "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
strNumberInText = numbers[Number / 10 - 2] + " " + ConvertToAmountInText(Number % 10, true, false);
}
else if (Number >= 100 && Number <= 999)
{
strNumberInText = ConvertToAmountInText(Number / 100, true, false) + " Hundred " + ConvertToAmountInText(Number % 100, true, false);
}
else if (Number >= 1000 && Number <= 999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000, true, false) + " Thousand " + ConvertToAmountInText(Number % 1000, true, false);
}
else if (Number >= 1000000 && Number <= 999999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000000, true, false) + " Million " + ConvertToAmountInText(Number % 1000000, true, false);
}
else if (Number >= 1000000000)
{
strNumberInText = ConvertToAmountInText(Number / 1000000000, true, false) + " Billion " + ConvertToAmountInText(Number % 1000000, true, false);
}
if (ConvertDecimalPart)
{
double dblDecimalPart = 0.00;
dblDecimalPart = numberToConvert - ((long)numberToConvert);
strNumberInText += " and " + dblDecimalPart.ToString("F").Substring(2) + '/' + Math.Pow(10, dblDecimalPart.ToString("F").Length - 2).ToString();
}
return strNumberInText;
}
{
long Number = (long)numberToConvert;
string strNumberInText = "";
if (Number == 0)
return (BlankIfZero ? "" : "Zero");
else if (Number >= 1 && Number <= 19)
{
string[] numbers = {"One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"};
strNumberInText = numbers[Number - 1];
}
else if (Number >= 20 && Number <= 99)
{
string[] numbers = { "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
strNumberInText = numbers[Number / 10 - 2] + " " + ConvertToAmountInText(Number % 10, true, false);
}
else if (Number >= 100 && Number <= 999)
{
strNumberInText = ConvertToAmountInText(Number / 100, true, false) + " Hundred " + ConvertToAmountInText(Number % 100, true, false);
}
else if (Number >= 1000 && Number <= 999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000, true, false) + " Thousand " + ConvertToAmountInText(Number % 1000, true, false);
}
else if (Number >= 1000000 && Number <= 999999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000000, true, false) + " Million " + ConvertToAmountInText(Number % 1000000, true, false);
}
else if (Number >= 1000000000)
{
strNumberInText = ConvertToAmountInText(Number / 1000000000, true, false) + " Billion " + ConvertToAmountInText(Number % 1000000, true, false);
}
if (ConvertDecimalPart)
{
double dblDecimalPart = 0.00;
dblDecimalPart = numberToConvert - ((long)numberToConvert);
strNumberInText += " and " + dblDecimalPart.ToString("F").Substring(2) + '/' + Math.Pow(10, dblDecimalPart.ToString("F").Length - 2).ToString();
}
return strNumberInText;
}