Ejemplo n.º 1
0
        protected virtual ArrayList GetTeens(Triplet triplet)
        {
            ArrayList words = new ArrayList();

            if (triplet.Tens == 1 && triplet.Units != 0)
            {
                words.Add(_numbersDictionary.GetTeensWord(triplet.Units));
            }

            return(words);
        }
Ejemplo n.º 2
0
        protected virtual ArrayList GetUnits(Triplet triplet, int?tripletIndex)
        {
            ArrayList words = new ArrayList();

            if (triplet.Tens != 1 && triplet.Units > 0)
            {
                words.Add(_numbersDictionary.GetOnesWord(triplet.Units));
            }

            return(words);
        }
Ejemplo n.º 3
0
        protected virtual ArrayList GetHundreds(Triplet triplet)
        {
            ArrayList words = new ArrayList();

            if (triplet.Hundreds > 0)
            {
                words.Add(_numbersDictionary.GetHundredsWord(triplet.Hundreds));
            }

            return(words);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Split number to triples.
        /// E.g 12345 give 123 and 45
        /// </summary>
        /// <param name="number">Number</param>
        /// <returns>Array of triples</returns>
        public static Triplet[] ToTriplets(this long number)
        {
            ArrayList tripples = new ArrayList();

            while (number > 0)
            {
                Triplet triplet = new Triplet((int)(number % 1000));
                tripples.Add(triplet);

                number = (long)(number / 1000);
            }

            return(tripples.OfType <Triplet>().ToArray());
        }
Ejemplo n.º 5
0
        protected virtual ArrayList GetTens(Triplet triplet)
        {
            ArrayList words = new ArrayList();

            if (triplet.Tens == 1 && triplet.Units == 0 ||
                triplet.Tens > 1)
            {
                if (triplet.Units > 0)
                {
                    words.Add("und");
                }

                words.Add(_numbersDictionary.GetTensWord(triplet.Tens));
            }

            return(words);
        }
Ejemplo n.º 6
0
        protected override ArrayList GetUnits(Triplet triplet, int?tripletIndex)
        {
            ArrayList words = new ArrayList();

            if (triplet.Tens != 1 && triplet.Units > 0)
            {
                // 1, 2, 3
                words.Add(_numbersDictionary.GetOnesWord(triplet.Units));

                if (tripletIndex == 0 && triplet.Value == 1 ||
                    triplet.Hundreds != 0 && triplet.Units == 1)
                {
                    words.Add("s");
                }
            }

            return(words);
        }
Ejemplo n.º 7
0
        ///<inheritdoc/>
        public string ToWords(Triplet triplet, int?tripletIndex, string numberSeparator)
        {
            ArrayList words = new ArrayList();

            // 100, 200, 300
            words.AddRange(GetHundreds(triplet));

            // 1, 2, 3
            words.AddRange(GetUnits(triplet, tripletIndex));

            // 11, 12 ,13
            words.AddRange(GetTeens(triplet));

            // 10, 20, 30
            words.AddRange(GetTens(triplet));

            return(string.Join(numberSeparator, words.ToArray()));
        }