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%