Build wheels: C #. ToString () formatting

Source: Internet
Author: User

Address: http://www.cnblogs.com/bignjl/archive/2011/01/14/1935645.html

format Specifier Declaration example output
C Currency 2.5.ToString ("C") ¥2.50
D decimal number 25.ToString ("D5") 00025
e-Scientific 25000.ToString ("E") 2.500000E+005
F fixed point 25.ToString ("F2") 25.00
G Regular 2.5.ToString ("G") 2.5
N Digital 2500000.ToString ("n") 2,500,000.00
X hex 255.ToString ("x") FF

String.Format formatting examples for C #
Stringstr1 =string.               Format ("{0:n1}", 56789); result:56,789.0
STRINGSTR2 =string.               Format ("{0:n2}", 56789); result:56,789.00
STRINGSTR3 =string.               Format ("{0:n3}", 56789); result:56,789.000
Stringstr8 =string.               Format ("{0:f1}", 56789); result:56789.0
STRINGSTR9 =string.               Format ("{0:f2}", 56789); result:56789.00
Stringstr11 = (56789/100.0).           ToString ("#.##"); result:567.89
Stringstr12 = (56789/100).             ToString ("#.##"); result:567

C or C
Currency
Console.Write ("{0:c}", 2.5); $2.50
Console.Write ("{0:c}",-2.5); ($2.50)

D or D
Decimal number
Console.Write ("{0:d5}", 25); 00025

E or E
Scientific type
Console.Write ("{0:e}", 250000); 2.500000E+005

F or F
Fixed point
Console.Write ("{0:f2}", 25); 25.00
Console.Write ("{0:f0}", 25); 25

G or G
Conventional
Console.Write ("{0:g}", 2.5); 2.5

N or N
Digital
Console.Write ("{0:n}", 2500000); 2,500,000.00

X or X
Hexadecimal
Console.Write ("{0:x}", 250); FA
Console.Write ("{0:x}", 0xFFFF); FFFF

Build wheels: C #. ToString () formatting

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.