标准格式化输出double类型的值可以使用以下格式字符串:
示例代码:
double number = 1234.5678;
Console.WriteLine(number.ToString("F2")); // 输出:1234.57
Console.WriteLine(number.ToString("N")); // 输出:1,234.57
Console.WriteLine(number.ToString("C")); // 输出:$1,234.57
Console.WriteLine(number.ToString("P")); // 输出:123,457.00%
Console.WriteLine(number.ToString("E")); // 输出:1.234568E+003
Console.WriteLine(number.ToString("G")); // 输出:1234.5678
Console.WriteLine(number.ToString("0.000")); // 输出:1234.568