SetCollectionWithDigits

Apr 27, 2012 at 11:08 PM

        /// <summary>
        /// Sets the collection with digits.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <param name="collection">The collection.</param>
        public static void SetCollectionWithDigits(double number, ObservableCollection<byte?> collection)
        {
            if (collection == null) return;
            var x = Convert.ToInt32(100 * (Math.Round(number, 2)));
            if (x <= 1e2) return;
            if (collection.Count < 2) return;
            collection[0] = MathUtility.GetDigitInNumber(x, 1);
            collection[1] = MathUtility.GetDigitInNumber(x, 2);

            x = Convert.ToInt32(MathUtility.TruncateNumber(number));
            if (x <= 1e0) return;
            if (collection.Count < 3) return;
            collection[2] = MathUtility.GetDigitInNumber(x, 1);

            if (x <= 1e1) return;
            if (collection.Count < 4) return;
            collection[3] = MathUtility.GetDigitInNumber(x, 2);

            if (x <= 1e2) return;
            if (collection.Count < 5) return;
            collection[4] = MathUtility.GetDigitInNumber(x, 3);

            if (x <= 1e3) return;
            if (collection.Count < 6) return;
            collection[5] = MathUtility.GetDigitInNumber(x, 4);

            if (x <= 1e4) return;
            if (collection.Count < 7) return;
            collection[6] = MathUtility.GetDigitInNumber(x, 5);

            if (x <= 1e5) return;
            if (collection.Count < 8) return;
            collection[7] = MathUtility.GetDigitInNumber(x, 6);
        }