예제 #1
0
        public static String ConvertDecimals(String number)
        {
            String result = "", digit = "", ones = "";

            for (int i = 0; i < number.Length; i++)
            {
                digit = number[i].ToString();
                if (digit.Equals("0"))
                {
                    ones = "Zero";
                }
                else
                {
                    ones = Ones.ones(digit);
                }
                result += " " + ones;
            }
            return(result);
        }
예제 #2
0
        public static String ConvertWholeNumber(String Number)
        {
            string word = "";

            try
            {
                bool   beginsZero = false; //tests for 0XX
                bool   isDone     = false; //test if already translated
                double dblAmt     = (Convert.ToDouble(Number));
                if (dblAmt > 0)
                {//test for zero or digit zero in a nuemric
                    beginsZero = Number.StartsWith("0");
                    int    numDigits = Number.Length;
                    int    pos       = 0;  //store digit grouping
                    String place     = ""; //digit grouping name:hundres,thousand,etc...
                    switch (numDigits)
                    {
                    case 1:    //ones' range
                        word   = Ones.ones(Number);
                        isDone = true;
                        break;

                    case 2:    //tens' range
                        word   = Tens.tens(Number);
                        isDone = true;
                        break;

                    case 3:    //hundreds' range
                        pos   = (numDigits % 3) + 1;
                        place = " Hundred ";
                        break;

                    case 4:    //thousands' range
                    case 5:
                    case 6:
                        pos   = (numDigits % 4) + 1;
                        place = " Thousand ";
                        break;

                    case 7:    //millions' range
                    case 8:
                    case 9:
                        pos   = (numDigits % 7) + 1;
                        place = " Million ";
                        break;

                    case 10:    //Billions's range
                    case 11:
                    case 12:
                        pos   = (numDigits % 10) + 1;
                        place = " Billion ";
                        break;

                    default:
                        isDone = true;
                        break;
                    }
                    if (!isDone)
                    {//Recursion
                        if (Number.Substring(0, pos) != "0" && Number.Substring(pos) != "0")
                        {
                            try
                            {
                                word = ConvertWholeNumber(Number.Substring(0, pos)) + place + ConvertWholeNumber(Number.Substring(pos));
                            }
                            catch { }
                        }
                        else
                        {
                            word = ConvertWholeNumber(Number.Substring(0, pos)) + ConvertWholeNumber(Number.Substring(pos));
                        }
                    }
                    //ignore digit grouping names
                    if (word.Trim().Equals(place.Trim()))
                    {
                        word = "";
                    }
                }
            }
            catch { }
            return(word.Trim());
        }
예제 #3
0
        public static String tens(String Number)
        {
            int    _Number = Convert.ToInt32(Number);
            String name    = null;

            switch (_Number)
            {
            case 10:
                name = "Ten";
                break;

            case 11:
                name = "Eleven";
                break;

            case 12:
                name = "Twelve";
                break;

            case 13:
                name = "Thirteen";
                break;

            case 14:
                name = "Fourteen";
                break;

            case 15:
                name = "Fifteen";
                break;

            case 16:
                name = "Sixteen";
                break;

            case 17:
                name = "Seventeen";
                break;

            case 18:
                name = "Eighteen";
                break;

            case 19:
                name = "Nineteen";
                break;

            case 20:
                name = "Twenty";
                break;

            case 30:
                name = "Thirty";
                break;

            case 40:
                name = "Fourty";
                break;

            case 50:
                name = "Fifty";
                break;

            case 60:
                name = "Sixty";
                break;

            case 70:
                name = "Seventy";
                break;

            case 80:
                name = "Eighty";
                break;

            case 90:
                name = "Ninety";
                break;

            default:
                if (_Number > 0)
                {
                    name = tens(Number.Substring(0, 1) + "0") + " " + Ones.ones(Number.Substring(1));
                }
                break;
            }
            return(name);
        }