當前位置: 首頁>>代碼示例>>C#>>正文


C# NumberFormatInfo.Format方法代碼示例

本文整理匯總了C#中System.Globalization.NumberFormatInfo.Format方法的典型用法代碼示例。如果您正苦於以下問題:C# NumberFormatInfo.Format方法的具體用法?C# NumberFormatInfo.Format怎麽用?C# NumberFormatInfo.Format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Globalization.NumberFormatInfo的用法示例。


在下文中一共展示了NumberFormatInfo.Format方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToString

        public static string ToString(double[][] counts, int cellSize, Object[] rowLabels, Object[] colLabels, NumberFormatInfo nf, bool printTotals)
        {
            if (counts == null)
                return null;
            double[] rowTotals = new double[counts.Length];
            double[] colTotals = new double[counts[0].Length];
            double total = 0.0;
            for (int i = 0; i < counts.Length; i++)
            {
                for (int j = 0; j < counts[i].Length; j++)
                {
                    rowTotals[i] += counts[i][j];
                    colTotals[j] += counts[i][j];
                    total += counts[i][j];
                }
            }

            StringBuilder result = new StringBuilder();
            if (colLabels != null)
            {
                result.Append(StringUtils.PadLeft(@"", cellSize));
                for (int j = 0; j < counts[0].Length; j++)
                {
                    string s = colLabels[j].ToString();
                    if (s.Length > cellSize - 1)
                    {
                        s = s.Substring(0, cellSize - 1);
                    }

                    s = StringUtils.PadLeft(s, cellSize);
                    result.Append(s);
                }

                if (printTotals)
                {
                    result.Append(StringUtils.PadLeftOrTrim(@"Total", cellSize));
                }

                result.Append('\n');
            }

            for (int i = 0; i < counts.Length; i++)
            {
                if (rowLabels != null)
                {
                    string s = rowLabels[i].ToString();
                    s = StringUtils.PadOrTrim(s, cellSize);
                    result.Append(s);
                }

                for (int j = 0; j < counts[i].Length; j++)
                {
                    result.Append(StringUtils.PadLeft((counts[i][j]).ToString(nf), cellSize));
                }

                if (printTotals)
                {
                    result.Append(StringUtils.PadLeft((rowTotals[i]).ToString(nf), cellSize));
                }

                result.Append('\n');
            }

            if (printTotals)
            {
                result.Append(StringUtils.Pad(@"Total", cellSize));
                foreach (double colTotal in colTotals)
                {
                    result.Append(StringUtils.PadLeft(nf.Format(colTotal), cellSize));
                }

                result.Append(StringUtils.PadLeft(nf.Format(total), cellSize));
            }

            return result.ToString();
        }
開發者ID:sandily,項目名稱:Stanford.NER.Net,代碼行數:76,代碼來源:ArrayMath.cs


注:本文中的System.Globalization.NumberFormatInfo.Format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。