控制台输出时小数位数定义
using System; namespace program { class program1 { static void Main(string[] args) { int a = 4, b = 5, c = 6; int p = (a + b + c) / 2; double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c)); Console.WriteLine("三角形的面积是{0:f2}", s);//保留两位小数 } } }