Code:
1 ///2 /// ToStringFormat 3 /// 创建人:Carl.Yang 4 /// 创建日期:2011-11-11 5 /// 6 /// 7 static void Main(string[] args) 8 { 9 decimal price1 = 99.6547M; 10 decimal price2 = 99.6544M; 11 12 //要截取的长度 13 int length = 3; 14 //F03 15 string format = string.Format("F0{0}", length); 16 17 Console.WriteLine(price1.ToString(format)); 18 Console.WriteLine(price2.ToString(format)); 19 Console.ReadLine(); 20 }
输出结果:
//99.655 //99.654