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