String. Format description

Source: Internet
Author: User

C # format the value result table

Character

Description

Example

Output

C currency String. Format("{0: C3}", 2) $2.000 D decimal String. Format("{0: D3}", 2) 002 E scientific notation 1.20E + 001 1.20E + 001G conventional String. Format("{0: G}", 2) numbers separated by semicolons (;) String. Format("{0: N}", 250000) 250,000.00 X hexadecimal String. Format("{0: X000}", 12) C

String. Format("{0: 000. 000}", 12.2) 012.200 Strings

There really isnt any formatting within a strong, beyond its alignment. Alignment works for any argument being printed in a String. Format call.

 

Sample GeneratesString. format ("-> {, 10} <-", "Hello");-> Hello <-String. format ("-> {1,-10} <-", "Hello");-> Hello <-

Numbers

Basic number formatting specifiers:

 

Specifier Type Format

Output
(Passed
Double 1.42)

Output
(Passed
Int-12400)

C Currency {0: c} $1.42-$12,400 d Decimal (Whole number) {0: d} System.
FormatException
-12400 e Scientific {0: e} 1.420000e + 000-1.2420.e + 004 f Fixed point {0: f} 1.42-12400.00g General {0: g} 1.42-12400 n Number with commas for thousands {0: n} 1.42-12,400 r Round trippable {0: r} 1.42 System.
FormatException
X Hexadecimal {0: x4} System.
FormatException
Cf90

Custom number formatting:

 

Specifier

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.