예제 #1
0
        public string Describe(int number, ZeroMode zeroMode)
        {
            var builder = new StringBuilder();
            var useAnd  = false;

            var thousands = number / 1000;

            number %= 1000;
            var hundreds = number / 100;

            number %= 100;
            var tens = number / 10;

            number %= 10;

            if (thousands > 0)
            {
                builder.Append(Describe(thousands, zeroMode));
                builder.Append(" ");
                builder.Append(_numberTokens[28]);
                useAnd = true;
            }

            if (hundreds > 0)
            {
                if (useAnd)
                {
                    builder.Append(" ");
                }
                builder.Append(Describe(hundreds, zeroMode));
                builder.Append(" ");
                builder.Append(_numberTokens[27]);
                useAnd = true;
            }

            if (tens > 1)
            {
                if (useAnd)
                {
                    builder.Append(" and ");
                }
                builder.Append(_numberTokens[19 + tens - 2]);
                useAnd = false;
                if (number == 0)
                {
                    return(builder.ToString());
                }

                builder.Append(" ");
            }
            else if (tens == 1)
            {
                number += 10;
            }

            if (useAnd)
            {
                if (number == 0)
                {
                    return(builder.ToString());
                }

                builder.Append(" and ");
            }

            builder.Append(number == 0
                ? _zeroTokens[(int)zeroMode + 1]
                : _numberTokens[number - 1]);

            return(builder.ToString());
        }
 public void GivenTheZeroModeIs(ZeroMode zeroMode)
 {
     _zeroMode = zeroMode;
 }