有时候我们需要把一些字符串数字转换一个格式输出,那么就需要用到format()
具体查看以下例子吧!
string str1 =string.Format("{0:N1}",56789); //result: 56,789.0
string str2 =string.Format("{0:N2}",56789); //result: 56,789.00
string str3 =string.Format("{0:N3}",56789); //result: 56,789.000
string str8 =string.Format("{0:F1}",56789); //result: 56789.0
string str9 =string.Format("{0:F2}",56789); //result: 56789.00
string str11 =(56789 / 100.0).ToString("#.##"); //result: 567.89
string str12 =(56789 / 100).ToString("#.##"); //result: 567