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

FormatNumber() private method

Formats a number into a string with the specified number of decimal places.
private FormatNumber ( decimal number, bool adjustDecimalPlaces, int decimalPlacesToShow ) : string
number decimal The number.
adjustDecimalPlaces bool if set to true decimal places as adjusted].
decimalPlacesToShow int The number decimal places to show.
return string
        private string FormatNumber(decimal number, bool adjustDecimalPlaces, int decimalPlacesToShow)
        {
            string format = "0";

            if(adjustDecimalPlaces)
            {
                if(decimalPlacesToShow > 0)
                {
                    //
                    // Output a specific number of decimal places in thenumber
                    //
                    format += _decimalSeperator + format.PadRight(format.Length + decimalPlacesToShow - 1, '0');
                }
                else
                {
                    decimalPlacesToShow *= -1;
                    string multiplier = "1";
                    multiplier = multiplier.PadRight(decimalPlacesToShow + 1, char.Parse("0"));
                    var numbers = number.ToString(CultureInfo.InvariantCulture).Split('.');
                    return (Math.Truncate(decimal.Parse(numbers[0]) * int.Parse(multiplier)) / int.Parse(multiplier)).ToString(CultureInfo.InvariantCulture);
                }
            }
            else
            {
                //
                // Output the actual number of decimal places in the number
                //
                format += _decimalSeperator + "#############################";
            }

            return number.ToString(format);
        }