本文整理汇总了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();
}