Ejemplo n.º 1
0
        private static int ConvertStatement(string[] words)
        {
            int  convertedValue    = 0;
            int  currentMultiplier = 1;
            bool resetHundred      = false;

            for (int i = words.Length - 1; i >= 0; i--)
            {
                string word = words[i];

                convertedValue += NumericTermDatabase.GetTermValue(word) * currentMultiplier;

                if (resetHundred)
                {
                    currentMultiplier /= 100;
                    resetHundred       = false;
                }

                if (word.Equals("hundred"))
                {
                    currentMultiplier *= 100;
                    resetHundred       = true;
                }

                if (NumericTermDatabase.IsMagnitudeIdentifier(word))
                {
                    currentMultiplier *= 1000;
                }
            }

            return(convertedValue);
        }
Ejemplo n.º 2
0
        private static string ConvertPeriod(int period)
        {
            string convertedPeriod = "";

            int[] digits = FindDigits(period);

            if (digits.Length == 3)
            {
                convertedPeriod += NumericTermDatabase.GetDigitAsString(digits[0]);
                convertedPeriod += " hundred";

                if (digits[1] == 1)
                {
                    convertedPeriod += NumericTermDatabase.GetTeenAsString(digits[2]);
                    return(convertedPeriod);
                }

                if (digits[1] != 0)
                {
                    convertedPeriod += " " + NumericTermDatabase.GetTensPlaceAsString(digits[1]);
                }
                if (digits[2] != 0)
                {
                    convertedPeriod += " " + NumericTermDatabase.GetDigitAsString(digits[2]);
                }
            }
            else if (digits.Length == 2)
            {
                if (digits[0] == 1)
                {
                    convertedPeriod += NumericTermDatabase.GetTeenAsString(digits[1]);
                    return(convertedPeriod);
                }

                if (digits[0] != 0)
                {
                    convertedPeriod += NumericTermDatabase.GetTensPlaceAsString(digits[1]);
                }
                if (digits[1] != 0)
                {
                    convertedPeriod += " " + NumericTermDatabase.GetDigitAsString(digits[1]);
                }
            }
            else
            {
                convertedPeriod += NumericTermDatabase.GetDigitAsString(digits[0]);
            }

            return(convertedPeriod);
        }
Ejemplo n.º 3
0
        private static string ConvertNumber(int conversionNumber)
        {
            string convertedNumber = "";

            int[] periods = FindPeriods(conversionNumber);

            for (int i = 0; i < periods.Length; i++)
            {
                if (periods[i] != 0)
                {
                    convertedNumber += " " + ConvertPeriod(periods[i]) + " ";
                    convertedNumber += NumericTermDatabase.GetMagnitude(i, periods.Length);
                }
            }

            if (convertedNumber[convertedNumber.Length - 1] != ' ')
            {
                convertedNumber += " ";
            }

            return(convertedNumber);
        }