In daily development, there are many situations of format strings. I often forget it, and it is a little difficult to check it. So today I will spend some time organizing it.
The format string is formatted by numbers, dates, and enumerations.
I.
Replace each format item in the specified string with the text equivalent item of the value of the corresponding object.
String Str1 = string. Format ("{0: N1}", 56789 ); // Result: 56,789.0 String Str2 = string. Format ("{0: N2}", 56789 ); //
"Turn" http://blog.csdn.net/samsone/article/details/75567811. Formatted currency (related to system environment, Chinese system default format RMB, English system format USD)String. Format ("{0:c}", 0.2) results are: ¥0.20 (English operating system
1. Use {0 :?} Format
You can use the string. Format method or the console. Write method to format numeric results. The latter method calls string. format. Use a format string to specify the format. The following table contains supported standard
1. Formatted currency (related to system environment, Chinese system default format RMB, English system format USD)String. Format ("{0:c}", 0.2) results are: ¥0.20 (English operating system results: $0.20)The default formatting retains two decimal
Printf (), scanf ()
% C --------------- output a character
% D ----------------- output a signed decimal integer
% E (% E) ------------ output a real number of floating-point numbers in the form of normalized exponent. Only 6 digits are
Conversion specifiers in Format
Conversion specifier
% A (% A) floating point number, hexadecimal number, and p-(P-) Notation (C99)% C single character% D signed decimal integer% F floating point number (including float and doulbe)Floating Point
The following tables show the format specifiers recognized by the debugger.
Specifier
Format
Expression
Value displayed
D, I
Signed decimal integer
0xf000f065, d
-268373915
U
Unsigned decimal integer
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.