我已经看到了问题Odd decimal type behavior for ToString(IFormatProvider)
这是我的测试代码
// Define an array of numbers to display.
double[] numbers = { -1.5345e16, -123.4321, 19092.123, 1.1734231911290e16 };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };
foreach (double number in numbers)
{
Console.WriteLine("{0}:", Convert.ToString(number,
System.Globalization.CultureInfo.InvariantCulture));
foreach (string cultureName in cultureNames)
{
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
culture.NumberFormat.NumberGroupSizes = new int[] {2,2,3};
culture.NumberFormat.NumberDecimalDigits = 5;
Console.WriteLine(".ToString {0}: {1,20}",
culture.Name, number.ToString("N", culture));
Console.WriteLine("Convert.ToString {0}: {1,20}",
culture.Name, Convert.ToString(number, culture));
}
Console.WriteLine();
}
样本结果如下:
为什么 Convert.ToString 不应用该格式?
这是 Win7 Prof/VS2010+SP1Rel (10.0.40219.1)