internal static string FormatNumberCellAndGetPattern(Cell cell, ref double value, INumberFormatArgs arg)
        {
            if (cell.InnerStyle.HAlign == ReoGridHorAlign.General)
            {
                cell.RenderHorAlign = ReoGridRenderHorAlign.Right;
            }

            /*if (cell.DataFormat == CellDataFormatFlag.General)
             * {
             *      return Convert.ToString(value);
             * }*/

            short decimals     = 0;
            bool  useSeparator = false;
            NumberNegativeStyle negativeStyle = NumberNegativeStyle.Default;

            if (arg != null)
            {
                decimals      = arg.DecimalPlaces;
                useSeparator  = arg.UseSeparator;
                negativeStyle = arg.NegativeStyle;
            }

            // decimal places
            string decimalPlacePart = new string('0', decimals);

            // number
            string numberPart = (useSeparator ? "#,##0." : "0.") + decimalPlacePart;

            if ((negativeStyle & NumberNegativeStyle.CustomSymbol) == NumberNegativeStyle.DollarSymbol)
            {
                numberPart = "$" + numberPart;
            }
            if (value < 0)
            {
                if ((negativeStyle & NumberNegativeStyle.Red) != 0)
                {
                    cell.RenderColor = SolidColor.Red;
                }
                else
                {
                    cell.RenderColor = SolidColor.Transparent;
                }
                if ((negativeStyle & NumberNegativeStyle.Brackets) != 0)
                {
                    numberPart = "(" + numberPart + ")";
                }
                else if ((negativeStyle & NumberNegativeStyle.Prefix_Sankaku) != 0)
                {
                    numberPart = "▲ " + numberPart;
                }
                if ((negativeStyle & NumberNegativeStyle.Minus) == 0)
                {
                    value = Math.Abs(value);
                }
            }
            return(numberPart);
        }
Exemple #2
0
        internal static string FormatNumberCellAndGetPattern(Cell cell, ref double value, INumberFormatArgs arg)
        {
            if (cell.InnerStyle.HAlign == ReoGridHorAlign.General)
            {
                cell.RenderHorAlign = ReoGridRenderHorAlign.Right;
            }

            short decimals     = 2;
            bool  useSeparator = true;
            NumberNegativeStyle negativeStyle = NumberNegativeStyle.Default;

            if (arg != null)
            {
                decimals      = arg.DecimalPlaces;
                useSeparator  = arg.UseSeparator;
                negativeStyle = arg.NegativeStyle;
            }

            if (value < 0)
            {
                if ((negativeStyle & NumberNegativeStyle.Red) == NumberNegativeStyle.Red)
                {
                    cell.RenderColor = SolidColor.Red;
                }
                else
                {
                    cell.RenderColor = SolidColor.Transparent;
                }
            }

            // decimal places
            string decimalPlacePart = new string('0', decimals);

            // number
            string numberPart = (useSeparator ? "#,##0." : "0.") + decimalPlacePart;

            if ((negativeStyle & NumberNegativeStyle.Brackets) == NumberNegativeStyle.Brackets)
            {
                numberPart = (value < 0) ? ("(" + numberPart + ")") : numberPart;
            }
            else if ((negativeStyle & NumberNegativeStyle.Prefix_Sankaku) == NumberNegativeStyle.Prefix_Sankaku)
            {
                numberPart = (value < 0) ? ("▲ " + numberPart) : numberPart;
            }

            // negative
            if ((negativeStyle & NumberNegativeStyle.Minus) == 0)
            {
                value = Math.Abs(value);
            }

            return(numberPart);
        }