c#string.format
字符串的数字格式
stringstr1 =string.Format("{0:N1}",56789); //result: 56,789.0stringstr2 =string.Format("{0:N2}",56789); //result: 56,789.00stringstr3 =string.Format("{0:N3}",56789); //result: 56,789.000stringstr8 =string.Format("{0:F1}",56789); //result: 56789.0stringstr9 =string.Format("{0:F2}",56789); //result: 56789.00stringstr11 =(56789 / 100.0).ToString("#.##"); //result: 567.89stringstr12 =(56789 / 100).ToString("#.##"); //result: 567C 或 c
货币
D 或 d
十进制数
E 或 e
科学型
F 或 f
固定点
G 或 g
常规
N 或 n
数字
X 或 x
十六进制
/////////////////////////////////////////////////////////////////////////////////
C#格式化数值结果表
Strings
There really isn't any formatting within a strong, beyond it's alignment. Alignment works for any argument being printed in a String.Format call.
Numbers
Basic number formatting specifiers:
Custom number formatting:
Dates
Note that date formatting is especially dependant on the system's regional settings; the example strings here are from my local locale.
Custom date formatting:
Enumerations
Some Useful Examples
String.Format("{0:$#,##0.00;($#,##0.00);Zero}", value);
This will output "$1,240.00" if passed 1243.50. It will output the same format but in parentheses if the number is negative, and will output the string "Zero" if the number is zero.
String.Format("{0:(###) ###-####}", 18005551212);
This will output "(800) 555-1212".
变量.ToString()
字符型转换 转为字符串
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%
java字符串格式化:String.format()方法的使用大全
字符型转换 转为字符串
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%
java字符串格式化:String.format()方法的使用大全
字符串格式化,即按照你想要的字符串格式输出,如时间显示格式等,下面这个网站介绍的相当全面。
参考网站:http://kgd1120.iteye.com/blog/1293633:
链接点击: String.format()方法的使用大全
实例:在android系统里面进行文件操作时,有时会使用当前时间,作为要保存数据的文件名,以便区别文件及日后对此文件进行操作。就如录像文件,当日保存下来的录像肯定会用当日的时间作为文件名称的一部分,方便以后查看。
如:
音视频项目中经常会用此文件命名方式。