Пример #1
0
        public static string ToBaht(this double number)
        {
            string[] word = number.ToString().Split('.');

            string inttext = NumberToWordExtensionMethods.IntToThaiWord(word[0]);
            string dectext = (word.Length > 1) ? (word[1].Length <= 2) ? ((inttext != string.Empty) ? "บาท" : string.Empty) + NumberToWordExtensionMethods.IntToThaiWord((word[1].Length == 1) ? word[1] + "0" : word[1]) + "สตางค์" : ((inttext != string.Empty) ? string.Empty : "ศูนย์") + "จุด" + NumberToWordExtensionMethods.DecToThaiWord(word[1]) + "บาท" : string.Empty;

            return((word.Length == 1) ? (inttext == string.Empty) ? "ศูนย์บาท" : inttext + "บาทถ้วน" : inttext + dectext);
        }
Пример #2
0
        public static string ToThaiWord(this double number)
        {
            string[] word = number.ToString().Split('.');

            string inttext = NumberToWordExtensionMethods.IntToThaiWord(word[0]);
            string dectext = (word.Length > 1) ? NumberToWordExtensionMethods.DecToThaiWord(word[1]) : string.Empty;

            return((word.Length == 1) ? ((inttext != string.Empty) ? inttext : "ศูนย์") : string.Format("{0}จุด{1}", (inttext != string.Empty) ? inttext : "ศูนย์", dectext));
        }
Пример #3
0
        private static string IntToThaiWord(string str)
        {
            List <string> word = new List <string>();
            List <string> num  = NumberToWordExtensionMethods.SplitString(str, 6);

            for (int i = 0; i < num.Count; i++)
            {
                string numThai = NumberToWordExtensionMethods.NumToThai(num[i]) + string.Join(string.Empty, Enumerable.Repeat <string>("ล้าน", i).ToArray());

                word.Add(numThai);
            }

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

            return(string.Join(string.Empty, result));
        }
Пример #4
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));
        }
Пример #5
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);
        }
Пример #6
0
 public static string ToThai(this double number)
 {
     return(NumberToWordExtensionMethods.ThaiNumber(number.ToString()));
 }
Пример #7
0
 public static string ToThai(this double number, IFormatProvider format)
 {
     return(NumberToWordExtensionMethods.ThaiNumber(number.ToString(format)));
 }