Example #1
0
        private static string IntToWord(string str)
        {
            string[] scale = new string[] { string.Empty, "Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintillion" };

            List <string> word = new List <string>();
            List <string> num  = NumberToWordExtensionMethods.SplitString(str, 3);

            for (int i = 0; i < num.Count; i++)
            {
                string numEng = NumberToWordExtensionMethods.NumToEng(num[i]) + ((scale[i] != string.Empty) ? string.Format(" {0}", scale[i]) : string.Empty);

                word.Add(numEng);
            }

            string[] result = word.ToArray();
            Array.Reverse(result);

            return(string.Join(" ", result));
        }
Example #2
0
        private static string NumToEng(string str)
        {
            string[] small = new string[] { string.Empty, "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
            string[] teens = new string[] { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
            string[] tens  = new string[] { string.Empty, string.Empty, "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };

            string result = string.Empty;

            if (str.Length == 2)
            {
                if (str.Substring(1, 1) == "1")
                {
                    result = teens[int.Parse(str.Substring(0, 1))];
                }
                else
                {
                    string one = small[int.Parse(str.Substring(0, 1))];

                    result = tens[int.Parse(str.Substring(1, 1))] + ((one != string.Empty) ? string.Format(" {0}", one) : string.Empty);
                }
            }
            else
            {
                if (str.Length == 3)
                {
                    string three = small[int.Parse(str.Substring(2))];
                    string two   = NumberToWordExtensionMethods.NumToEng(str.Substring(0, 2));

                    result = ((three != string.Empty) ? string.Format("{0} Hundred", three) : string.Empty) + ((two != string.Empty) ? string.Format(" and {0}", two) : string.Empty);
                }
                else
                {
                    result = small[int.Parse(str)];
                }
            }

            return(result);
        }