// ReSharper disable InconsistentNaming
        private string BuildRoundingExpression(IFormatNumberTO formatNumberTO)
        // ReSharper restore InconsistentNaming
        {
            string expression;

            enRoundingType roundingType = formatNumberTO.GetRoundingTypeEnum();

            if (roundingType == enRoundingType.Normal)
            {
                expression = "round({0}, {1})";
            }
            else if (roundingType == enRoundingType.Up)
            {
                expression = "roundup({0}, {1})";
            }
            else if (roundingType == enRoundingType.Down)
            {
                expression = "rounddown({0}, {1})";
            }
            else
            {
                expression = "{0}";
            }

            expression = string.Format(expression, formatNumberTO.Number, formatNumberTO.RoundingDecimalPlaces);

            return(expression);
        }
Пример #2
0
        string BuildRoundingExpression(IFormatNumberTO formatNumberTO)

        {
            string expression;

            var roundingType = formatNumberTO.GetRoundingTypeEnum();

            if (roundingType == enRoundingType.Normal)
            {
                expression = "round({0}, {1})";
            }
            else if (roundingType == enRoundingType.Up)
            {
                expression = "roundup({0}, {1})";
            }
            else if (roundingType == enRoundingType.Down)
            {
                expression = "rounddown({0}, {1})";
            }
            else
            {
                expression = "{0}";
            }

            expression = string.Format(expression, formatNumberTO.Number, formatNumberTO.RoundingDecimalPlaces);

            return(expression);
        }
Пример #3
0
        string Round(IFormatNumberTO formatNumberTO)

        {
            _functionEvaluator.TryEvaluateFunction(BuildRoundingExpression(formatNumberTO), out string result, out string error);

            if (!string.IsNullOrWhiteSpace(error))
            {
                throw new InvalidOperationException(error);
            }

            return(result);
        }
        // ReSharper disable InconsistentNaming
        private string Round(IFormatNumberTO formatNumberTO)
        // ReSharper restore InconsistentNaming
        {
            string error;
            string result;

            _functionEvaluator.TryEvaluateFunction(BuildRoundingExpression(formatNumberTO), out result, out error);

            if (!string.IsNullOrWhiteSpace(error))
            {
                throw new InvalidOperationException(error);
            }

            return(result);
        }
        // ReSharper restore InconsistentNaming

        #endregion Class Members

        #region Methods

        /// <summary>
        /// Formats a number.
        /// </summary>
        /// <param name="formatNumberTO">The information on how to format the number.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">formatNumberTO</exception>
        // ReSharper disable InconsistentNaming
        public string Format(IFormatNumberTO formatNumberTO)
        // ReSharper restore InconsistentNaming
        {
            if (formatNumberTO == null)
            {
                throw new ArgumentNullException("formatNumberTO");
            }

            if (formatNumberTO.RoundingDecimalPlaces < -14 || formatNumberTO.RoundingDecimalPlaces > 14)
            {
                throw new InvalidOperationException(string.Format(ErrorResource.RoundingDecimalPlaceBetween, "-14", "14"));
            }

            if (formatNumberTO.AdjustDecimalPlaces && (formatNumberTO.DecimalPlacesToShow < -14 || formatNumberTO.DecimalPlacesToShow > 14))
            {
                throw new InvalidOperationException(string.Format(ErrorResource.RoundingDecimalPlaceBetween, "-14", "14"));
            }

            string result = Round(formatNumberTO);

            result = AdjustDecimalPlaces(result, formatNumberTO.AdjustDecimalPlaces, formatNumberTO.DecimalPlacesToShow);
            return(result);
        }