String. Format (c# Java)

c#string. format

Numeric format of string

C or C

currency

D or D

Decimal number

E or e

Scientific type

F or F

Fixed point

G or G

routine

N or n

number

X or X

hexadecimal

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

C# formatted numerical result table

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".

Variable ToString()

Character type conversion to string 12345 ToString("n"); // Generate 12345.00 ToString("C"); // Generate ¥ 12345.00 ToString("e"); // Generate 1.234500e + 004 12345 ToString("f4"); // Generate 12345.0000 ToString("x"); // Generate 3039 (HEX) 12345 ToString("p"); // Generate 1234500.00%

Java string format: string Use of format () method

Convert character type to string

12345.ToString("n"); // Generate 12345.00

12345.ToString("C"); // Generate ¥ 12345.00

12345.ToString("e"); // Generate 1.234500e + 004

12345.ToString("f4"); // Generate 12345.0000

12345.ToString("x"); // Generate 3039 (HEX)

12345.ToString("p"); // Generate 1500.00%

Java string format: string Use of format () method

String format, that is, output according to the string format you want, such as time display format, etc. the following website is quite comprehensive.

Reference website: http://kgd1120.iteye.com/blog/1293633 :

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>