Ejemplo n.º 1
0
        /// <Summary>
        ///     Formats the string to integer.
        ///     <code>Precondition: numericValue != null AND is a valid number</code>
        /// </Summary>
        /// <param name="numericValue">The numeric value.</param>
        /// <returns>The integer representation of that string</returns>
        public static int FormatStringToInteger(string numericValue)
        {
            if (!FormatValidator.IsNumericStringValid(numericValue))
            {
                throw new FormatException($"{nameof(numericValue)} is not a valid number");
            }

            if (numericValue == null)
            {
                return(0);
            }

            if (numericValue.Equals(string.Empty))
            {
                return(0);
            }

            var number = int.Parse(numericValue);

            if (number < 0)
            {
                number = 0;
            }

            return(number);
        }