Asp.net format function usage (c)

Source: Internet
Author: User
Tags print format

Format function return

Returns Variant (String), which contains an expression that is formatted according to the instructions in the format expression.

Syntax

Format (expression [, format [, firstdayofweek [, firstweekofyear])

The syntax of the C # Format function includes the following parts:

Description
Expression Parameters. Any valid expression.
The format parameter is optional. A valid naming expression or custom format expression.

Optional parameter of firstdayofweek. Constant, indicating the first day of a week.
Firstweekofyear is an optional parameter. Constant, indicating the first week of a year.

The C # Format function displays or prints a Date variable in a predefined Format. For example:
Print Format (d, "general date") '99-5-23 11:45:34
Print Format (d, "long date") 'August 1, May 23, 1999
Print Format (d, "medium date") '99-05-23
Print Format (d, "short date") '99-5-23
Print Format (d, "long time") '11: 45: 34
Print Format (d, "medium time") '11: 45 AM
Print Format (d, "short time") '11: 45

 

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 + 001
G General String. Format("{0: G}", 2) 2
N Number separated by semicolons String. Format("{0: N}", 250000) 250,000.00
X Hexadecimal String. Format("{0: X000}", 12) C


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

Example:
12345. ToString ("n"); // Generate 12,345.00
12345. ToString ("C"); // Generate $12,345.00
12345. ToString ("e"); // Generate 1.234500e + 004
12345. ToString ("f4"); // Generate 12345.0000
12345. ToString ("x"); // Generate 3039 (hexadecimal)
12345. ToString ("p"); // Generate 1,234,500.00%

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.