保留数位
namespace BasicGrammarStudy { class Program { static void Main(string[] args) { Console.WriteLine(string.Format("{0:F3}", 13.47483327438)); // 13.475 Console.WriteLine(string.Format("{0:N3}", 13.47483327438)); // 13.475 Console.WriteLine(string.Format("{0:F}", 13.47483327438)); // 13.47 Console.WriteLine(13.47483327438.ToString("0.###")); // 13.475 Console.WriteLine(Math.Round(13.47483327438, 3)); // 13.475 Console.WriteLine(Math.Round(13.47483327438, MidpointRounding.AwayFromZero)); // 13 Console.ReadKey(); } } } 输出: 13.475 13.475 13.47 13.475 13.475 13
标签:Console,string,示例,C#,代码,Format,13.475,13.47483327438,WriteLine From: https://www.cnblogs.com/zhaoke271828/p/17633250.html