Dev2.Data.Operations.Dev2NumberFormatter.Format C# (CSharp) Method

Format() public method

Formats a number.
formatNumberTO
public Format ( FormatNumberTO formatNumberTO ) : string
formatNumberTO Dev2.Data.TO.FormatNumberTO The information on how to format the number.
return string
        public string Format(FormatNumberTO formatNumberTO)
        // ReSharper restore InconsistentNaming
        {
            if(formatNumberTO == null)
            {
                throw new ArgumentNullException("formatNumberTO");
            }

            if(formatNumberTO.RoundingDecimalPlaces < -14 || formatNumberTO.RoundingDecimalPlaces > 14)
            {
                throw new InvalidOperationException("Rounding decimal places must be between -14 and 14.");
            }

            if(formatNumberTO.AdjustDecimalPlaces && (formatNumberTO.DecimalPlacesToShow < -14 || formatNumberTO.DecimalPlacesToShow > 14))
            {
                throw new InvalidOperationException("Decimal places to show must be less between -14 than 14.");
            }

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

Usage Example

        public void Format_Given_NegativeNumber_Where_RoundingDecimalPlacesAreNegative_Expected_RoundingToMultiplesOf10ForEveryNegative()
        {
            FormatNumberTO formatNumberTO = new FormatNumberTO("-123.12345", enRoundingType.Normal, -1, false, 0);
            Dev2NumberFormatter dev2NumberFormatter = new Dev2NumberFormatter();
            string actual = dev2NumberFormatter.Format(formatNumberTO);
            double expectedDouble = -120d;
            string expected = expectedDouble.ToString();

            Assert.AreEqual(expected, actual);
        }
All Usage Examples Of Dev2.Data.Operations.Dev2NumberFormatter::Format