double a = 123456, b = 123456.1, c = 123456.12, d = 123456.123, e = 123456.126;Console.WriteLine(a.ToString("N")); //123,456.00Console.WriteLine(b.ToString("N")); //123,456.10Console.WriteLine(c.ToString("N")); //123,456.12Console.WriteLine(d.ToString("N")); //123,456.12Console.WriteLine(e.ToString("N")); //123,456.13Console.WriteLine();Console.WriteLine(a.ToString("N2")); //123,456.00Console.WriteLine(b.ToString("N2")); //123,456.10Console.WriteLine(c.ToString("N2")); //123,456.12Console.WriteLine(d.ToString("N2")); //123,456.12Console.WriteLine(e.ToString("N2")); //123,456.13Console.WriteLine();Console.WriteLine(a.ToString("F2")); //123456.00Console.WriteLine(b.ToString("F2")); //123456.10Console.WriteLine(c.ToString("F2")); //123456.12Console.WriteLine(d.ToString("F2")); //123456.12Console.WriteLine(e.ToString("F2")); //123456.13Console.WriteLine();Console.WriteLine(a.ToString("0.00")); //123456.00Console.WriteLine(b.ToString("0.00")); //123456.10Console.WriteLine(c.ToString("0.00")); //123456.12Console.WriteLine(d.ToString("0.00")); //123456.12Console.WriteLine(e.ToString("0.00")); //123456.13Console.WriteLine();Console.WriteLine(a.ToString("G")); //123456Console.WriteLine(b.ToString("G")); //123456.1Console.WriteLine(c.ToString("G")); //123456.12Console.WriteLine(d.ToString("G")); //123456.123Console.WriteLine(e.ToString("G")); //123456.126Console.WriteLine();//本地货币Console.WriteLine(a.ToString("C")); //NT$123,456Console.WriteLine(b.ToString("C")); //NT$123,456.1Console.WriteLine(c.ToString("C")); //NT$123,456.12Console.WriteLine(d.ToString("C")); //NT$123,456.123Console.WriteLine(e.ToString("C")); //NT$123,456.126Console.WriteLine();Console.Read();
原创:c# 数字转字符串保留两位小数 - HotSky - 博客园 (cnblogs.com)