String.Format大全(C# Java)

2019-12-26 13:16:01王旭

/////////////////////////////////////////////////////////////////////////////////

C#格式化数值结果表

String.Format大全(C# Java)

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.

String.Format大全(C# Java)

Numbers

Basic number formatting specifiers:

String.Format大全(C# Java)

Custom number formatting:

String.Format大全(C# Java)

Dates

Note that date formatting is especially dependant on the system's regional settings; the example strings here are from my local locale.

String.Format大全(C# Java)

Custom date formatting:

String.Format大全(C# Java)

Enumerations

String.Format大全(C# Java)

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