The Format function formats the Expr argument according to the specified statements and returns the formatted expression.
Syntax | ||||
Format(Expr , [FormatString [,FirstDayOfWeek [,FirstWeekOfYear ]]]) | ||||
Return value | ||||
Type |
Description | |||
String |
Formatted string of Expr. | |||
Parameter | ||||
Use |
Name |
Type |
Passing |
Description |
Required |
Expr |
Variant |
ByVal |
Expression to be formatted. |
Optional |
FormatString |
String |
ByVal |
Format specification |
Optional |
FirstDayOfWeek |
Long |
ByVal |
First day of the week |
Optional |
FirstWeekOfYear |
Long |
ByVal |
First week of the year |
Enter a valid format expression using the FormatString parameter.
If you want to specify different formats for positive and negative values, as well as for the null value, separate them with a semicolon:
Such as:
#,##0.00; - #,##0.00; \N\U\L\L
Use the following formatting (subject to change):
Format chars |
Description |
# |
Digit |
0 |
Digit, a zero is always output |
. (Dot) |
Decimal point |
, (Comma) |
Thousands |
/ |
Separators for dates |
: |
Separators for time indications |
DD |
Day |
MM |
Month |
MMM |
Month with longer naming |
W |
Day of the week |
Ww |
Week of the year |
Q |
Quarter of the year |
AMPM |
Before midday (A) / After midday (P) |
YY |
Year with two characters |
YYY |
Year with full naming |
YYYY |
Year with four chars |
Hh |
Hour |
Nn |
Minute |
Ss |
Second |
- |
Sign |
% |
Conversion to percent |
> |
Only uppercase |
< |
Only lower case |
X |
The first char |
X(10) |
Left aligned in ten spaces (maximum 10 characters), excess characters are cut off |
Z(10.2) |
Right aligned integer with ten Nulls, left aligned decimal with two Nulls |
\D |
Output of character D (Backslash before the character disables other meaning |
@ |
Right aligned output of text |
FirstDayOfWeek |
Description |
1 |
Sunday (Default) |
2 |
Monday |
3 |
Tuesday |
4 |
Wednesday |
5 |
Thursday |
6 |
Friday |
7 |
Saturday |
FirstWeekOfYear |
Description |
1 |
Week of the 1. January |
2 |
Week with at least four days in the new year |
3 |
First full week in the new year |
Note
When formatting a number without specifying format, format returns the same result as the Str function, even though it responds to the locale setting. However, for positive numbers formatted as strings, the leading space reserved for signs is missing. The numbers converted with Str retain the leading space.