static void Main(string[] args)
{
// Gets a NumberFormatInfo associated with the en-US culture.
NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;
// Displays a negative value with the default number of decimal digits (2).
double mydbl = 42873.1415926;
Console.WriteLine(mydbl.ToString("N", nfi));
Console.WriteLine(mydbl.ToString("f", nfi));
// Displays the same value with four decimal digits.
nfi.NumberDecimalDigits = 4;
Console.WriteLine(mydbl.ToString("N", nfi));
Console.WriteLine(mydbl.ToString("f", nfi));
double d = 42873.1415926;
Console.WriteLine(d.ToString("f4"));
Console.WriteLine(d.ToString("f04"));
Console.WriteLine(d.ToString("n4"));
Console.WriteLine(d.ToString("n04"));
}
{
// Gets a NumberFormatInfo associated with the en-US culture.
NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;
// Displays a negative value with the default number of decimal digits (2).
double mydbl = 42873.1415926;
Console.WriteLine(mydbl.ToString("N", nfi));
Console.WriteLine(mydbl.ToString("f", nfi));
// Displays the same value with four decimal digits.
nfi.NumberDecimalDigits = 4;
Console.WriteLine(mydbl.ToString("N", nfi));
Console.WriteLine(mydbl.ToString("f", nfi));
double d = 42873.1415926;
Console.WriteLine(d.ToString("f4"));
Console.WriteLine(d.ToString("f04"));
Console.WriteLine(d.ToString("n4"));
Console.WriteLine(d.ToString("n04"));
}
运行结果