Format 函数Format function

返回一个 Variant (String) 值,其中包含根据格式表达式中所含指令设置格式的表达式Returns a Variant (String) containing an expression formatted according to instructions contained in a format expression.

备注

有兴趣开发跨多个平台扩展 Office 体验的解决方案吗?Interested in developing solutions that extend the Office experience across multiple platforms? 查看新的 Office 外接程序模型Check out the new Office Add-ins model. 与VSTO外接程序和解决方案相比,Office外接程序占用的空间较小,您可以使用几乎任何Web编程技术(例如HTML5,JavaScript,CSS3和XML)来构建它们。Office Add-ins have a small footprint compared to VSTO Add-ins and solutions, and you can build them by using almost any web programming technology, such as HTML5, JavaScript, CSS3, and XML.

语法Syntax

Format(Expression, [ Format ], [ FirstDayOfWeek ], [ FirstWeekOfYear ])Format(Expression, [ Format ], [ FirstDayOfWeek ], [ FirstWeekOfYear ])


Format 函数语法包含以下各部分。The Format function syntax has these parts.

PartPart 说明Description
ExpressionExpression 必需。Required. 任何有效的表达式。Any valid expression.
FormatFormat 可选。Optional. 一个有效的指定格式表达式或用户定义的格式表达式。A valid named or user-defined format expression.
FirstDayOfWeekFirstDayOfWeek 可选。Optional. 一个指定一周的第一天的常量A constant that specifies the first day of the week.
FirstWeekOfYearFirstWeekOfYear 可选。Optional. 一个指定一年的第一周的常量。A constant that specifies the first week of the year.

设置Settings

firstdayofweek 参数 包含以下设置。The firstdayofweek argument has these settings.

常量Constant Value 说明Description
vbUseSystemvbUseSystem 00 使用 NLS API 设置。Use NLS API setting.
vbSundayvbSunday 11 周日(默认)Sunday (default)
vbMondayvbMonday 22 星期一Monday
vbTuesdayvbTuesday 33 星期二Tuesday
vbWednesdayvbWednesday 44 星期三Wednesday
vbThursdayvbThursday 55 星期四Thursday
vbFridayvbFriday 66 星期五Friday
vbSaturdayvbSaturday 77 星期六Saturday

firstweekofyear 参数 包含以下设置。The firstweekofyear argument has these settings.

常量Constant Value 说明Description
vbUseSystemvbUseSystem 00 使用 NLS API 设置。Use NLS API setting.
vbFirstJan1vbFirstJan1 11 从 1 月 1 日所在的周开始(默认)。Start with week in which January 1 occurs (default).
vbFirstFourDaysvbFirstFourDays 22 从一年中至少包含四天的第一周开始。Start with the first week that has at least four days in the year.
vbFirstFullWeekvbFirstFullWeek 33 从一年的第一个完整周开始。Start with the first full week of the year.

注解Remarks

格式化的对象To format 具体操作Do this
数字Numbers 使用预定义的指定数值格式或创建用户定义的数值格式。Use predefined named numeric formats or create user-defined numeric formats.
日期和时间Dates and times 使用预定义的指定日期/时间格式或创建用户定义的日期/时间格式。Use predefined named date/time formats or create user-defined date/time formats.
日期和时间序列号Date and time serial numbers 使用日期和时间格式或数值格式。Use date and time formats or numeric formats.
字符串Strings 创建您自己的用户定义的字符串格式。Create your own user-defined string formats.

Formatformat 截断为 257 字符。Format truncates format to 257 characters.

如果尝试设置数字格式而不指定 format,则 Format 提供类似于 Str 函数的功能(尽管它能够感知区域设置)。If you try to format a number without specifying format, Format provides functionality similar to the Str function, although it is internationally aware. 但是,通过使用 Format 将格式设置为字符串的正数不包括为值的符号保留的前导空格;使用 Str 转换这些数字可保留前导空格。However, positive numbers formatted as strings using Format don't include a leading space reserved for the sign of the value; those converted using Str retain the leading space.

如果您正在设置非本地化数值字符串的格式,则应使用用户定义的数值格式来确保获取所需外观。If you are formatting a non-localized numeric string, you should use a user-defined numeric format to ensure that you get the look you want.

备注

如果 Calendar 属性设置为 Gregorianformat 指定了日期格式,则提供的 expression 必须为 GregorianIf the Calendar property setting is Gregorian and format specifies date formatting, the supplied expression must be Gregorian. 如果 Visual Basic Calendar 属性设置为 Hijri,则提供的 expression 必须为 HijriIf the Visual Basic Calendar property setting is Hijri, the supplied expression must be Hijri.

如果日历为公历,则 format 表达式符号的含义不变。If the calendar is Gregorian, the meaning of format expression symbols is unchanged. 如果日历为回历,则所有日期格式符号(例如,ddddmmmmyyyy)都具有相同的含义,但适用于回历。If the calendar is Hijri, all date format symbols (for example, dddd, mmmm, yyyy ) have the same meaning but apply to the Hijri calendar. 格式符号保留为英文;导致文本显示的符号(如 AM 和 PM)会显示与该符号关联的字符串(英语或阿拉伯语)。Format symbols remain in English; symbols that result in text display (for example, AM and PM) display the string (English or Arabic) associated with that symbol. 当日历为 Hijri 时,某些符号的范围会发生更改。The range of certain symbols changes when the calendar is Hijri.

日期符号Date symbols

符号Symbol 范围Range
dd 1-31(月份中的某一日,不带前导零)1-31 (Day of month, with no leading zero)
dddd 01-31(月份中的某一日,带前导零)01-31 (Day of month, with a leading zero)
ww 1-7(星期几,从星期日 = 1 开始)1-7 (Day of week, starting with Sunday = 1)
wwww 1-53(年份中的某一周,不带前导零;第 1 周从 1 月 1 日开始)1-53 (Week of year, with no leading zero; Week 1 starts on Jan 1)
mm 1-12(年份中的某一月,不带前导零;从 1 月 = 1 开始)1-12 (Month of year, with no leading zero, starting with January = 1)
mmmm 01-12(年份中的某一月,带前导零;从 1 月 = 01 开始)01-12 (Month of year, with a leading zero, starting with January = 01)
mmmmmm 显示缩写的月份名称(Hijri 月份名称没有缩写形式)Displays abbreviated month names (Hijri month names have no abbreviations)
mmmmmmmm 显示完整的月份名称Displays full month names
yy 1-366(年份中的某一天)1-366 (Day of year)
yyyy 00-99(年份的最后两位数)00-99 (Last two digits of year)
yyyyyyyy 100-9999(三位或四位数年份)100-9999 (Three- or Four-digit year)

时间符号Time symbols

符号Symbol 范围Range
hh 0-23(在 1-12 时附加“AM”或“PM”)(一天中的小时数,不带前导零)0-23 (1-12 with "AM" or "PM" appended) (Hour of day, with no leading zero)
hhhh 00-23(在 01-12 时附加“AM”或“PM”)(一天中的小时数,带前导零)00-23 (01-12 with "AM" or "PM" appended) (Hour of day, with a leading zero)
nn 0-59(小时内的分钟数,不带前导零)0-59 (Minute of hour, with no leading zero)
nnnn 00-59(小时内的分钟数,带前导零)00-59 (Minute of hour, with a leading zero)
mm 0-59(小时内的分钟数,不带前导零)。0-59 (Minute of hour, with no leading zero). 仅在前面带有 hhhOnly if preceded by h or hh
mmmm 00-59(小时内的分钟数,带前导零)。00-59 (Minute of hour, with a leading zero). 仅在前面带有 hhhOnly if preceded by h or hh
ss 0-59(分钟内的秒数,不带前导零)0-59 (Second of minute, with no leading zero)
ssss 00-59(分钟内的秒数,带前导零)00-59 (Second of minute, with a leading zero)

示例Example

本示例演示 Format 函数的各种用途以使用命名格式和用户定义格式设置值的格式。This example shows various uses of the Format function to format values using both named formats and user-defined formats. 对于日期分隔符 (/)、时间分隔符 (:) 和 AM/PM 文本,系统显示的实际格式化输出取决于运行代码时所基于的区域设置。For the date separator (/), time separator (:), and AM/ PM literal, the actual formatted output displayed by your system depends on the locale settings on which the code is running. 在开发环境中显示时间和日期时,将使用代码区域设置的短时间格式和短日期格式。When times and dates are displayed in the development environment, the short time format and short date format of the code locale are used. 在通过运行代码显示日期和时间时,将使用系统区域设置的短时间格式和短日期格式,这可能与代码区域设置所采用的格式不同。When displayed by running code, the short time format and short date format of the system locale are used, which may differ from the code locale. 对于此示例,假定使用 English/U.S.。For this example, English/U.S. is assumed. 在开发环境中使用当前系统的短时间设置和短日期设置显示 MyTimeMyDateMyTime and MyDate are displayed in the development environment using current system short time setting and short date setting.

Dim MyTime, MyDate, MyStr
MyTime = #17:04:23#
MyDate = #January 27, 1993#

' Returns current system time in the system-defined long time format.
MyStr = Format(Time, "Long Time")

' Returns current system date in the system-defined long date format.
MyStr = Format(Date, "Long Date")

MyStr = Format(MyTime, "h:m:s")    ' Returns "17:4:23".
MyStr = Format(MyTime, "hh:mm:ss am/pm")    ' Returns "05:04:23 pm".
MyStr = Format(MyTime, "hh:mm:ss AM/PM")    ' Returns "05:04:23 PM".
MyStr = Format(MyDate, "dddd, mmm d yyyy")    ' Returns "Wednesday, Jan 27 1993".
' If format is not supplied, a string is returned.
MyStr = Format(23)    ' Returns "23".

' User-defined formats.
MyStr = Format(5459.4, "##,##0.00")    ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00")    ' Returns "334.90".
MyStr = Format(5, "0.00%")    ' Returns "500.00%".
MyStr = Format("HELLO", "<")    ' Returns "hello".
MyStr = Format("This is it", ">")    ' Returns "THIS IS IT".

针对不同数值的不同格式Different formats for different numeric values

针对数字的用户定义的格式表达式可包含 1 到 4 个部分,它们之间用分号分隔开。A user-defined format expression for numbers can have from one to four sections separated by semicolons. 如果格式参数包含某个指定数值格式,则仅允许有一个部分。If the format argument contains one of the named numeric formats, only one section is allowed.

如果使用If you use 结果为The result is
仅一个部分One section only 格式表达式适用于所有值。The format expression applies to all values.
两个部分Two sections 第一个部分适用于正值和零,第二个部分适用于负值。The first section applies to positive values and zeros, the second to negative values.
三个部分Three sections 第一个部分适用于正值,第二个部分适用于负值,第三个部分适用于零。The first section applies to positive values, the second to negative values, and the third to zeros.
四个部分Four sections 第一个部分适用于正值,第二个部分适用于负值,第三个部分适用于零,第四部分适用于 Null 值。The first section applies to positive values, the second to negative values, the third to zeros, and the fourth to Null values.
"$#,##0;($#,##0)"

如果包含两个连续的分号,则缺少的部分用正值的格式显示。If you include semicolons with nothing between them, the missing section is printed using the format of the positive value. 例如,以下格式显示采用第一部分中的格式的正值和负值,并且显示"零"(如果值为零)。For example, the following format displays positive and negative values using the format in the first section and displays "Zero" if the value is zero.

"$#,##0;;\Z\e\r\o"

针对不同字符串值的不同格式Different formats for different string values

针对字符串的格式表达式可包括一个或两个部分(由分号 (;) 分隔)。A format expression for strings can have one section or two sections separated by a semicolon (;).

在使用以下各项的情况下If you use 结果为The result is
仅一个部分One section only 格式适用于所有字符串数据。The format applies to all string data.
两个部分Two sections 第一个部分适用于字符串数据,第二个部分适用于 Null 值和零长度字符串 ("")。The first section applies to string data, the second to Null values and zero-length strings ("").

命名的日期/时间格式Named date/time formats

下表标识了预定义的日期和时间格式名称。The following table identifies the predefined date and time format names.

格式名称Format name 说明Description
General DateGeneral Date 显示日期和/或时间,例如,1993 年 4 月 3 日 05:34 PM。Display a date and/or time, for example, 4/3/93 05:34 PM. 如果没有小数部分,则只显示日期,例如,1993 年 4 月 3 日。If there is no fractional part, display only a date, for example, 4/3/93. 如果没有整数部分,则只显示时间,例如,05:34 PM。If there is no integer part, display time only, for example, 05:34 PM. 日期显示由系统设置确定。Date display is determined by your system settings.
Long DateLong Date 根据您系统的长日期格式显示日期。Display a date according to your system's long date format.
Medium DateMedium Date 使用适用于主机应用程序的语言版本的中日期格式显示日期。Display a date using the medium date format appropriate for the language version of the host application.
Short DateShort Date 使用您系统的短日期格式显示日期。Display a date using your system's short date format.
Long TimeLong Time 使用您系统的长时间格式显示时间;包括小时、分钟、秒。Display a time using your system's long time format; includes hours, minutes, seconds.
Medium TimeMedium Time 使用小时和分钟以及 AM/PM 指示符按 12 小时制格式显示时间。Display time in 12-hour format using hours and minutes and the AM/PM designator.
Short TimeShort Time 使用 24 小时制格式显示时间,例如 17:45。Display a time using the 24-hour format, for example, 17:45.

命名的数值格式Named numeric formats

下表标识了预定义的数值格式名称。The following table identifies the predefined numeric format names.

格式名称Format name 说明Description
General NumberGeneral Number 显示没有千位分隔符的数字。Display number with no thousand separator.
CurrencyCurrency 显示带千位分隔符的数字(如果适当);显示小数点右边的两位数。Display number with thousand separator, if appropriate; display two digits to the right of the decimal separator. 输出将基于系统区域设置Output is based on system locale settings.
FixedFixed 至少显示小数点左边的一位数和小数点右边的两位数。Display at least one digit to the left and two digits to the right of the decimal separator.
StandardStandard 显示带千位分隔符的数字,至少显示小数点左边的一位数和小数点右边的两位数。Display number with thousand separator, at least one digit to the left and two digits to the right of the decimal separator.
PercentPercent 显示乘以 100 之后得到的数字,并在右侧附加一个百分号 (%);始终显示小数点右边的两位数。Display number multiplied by 100 with a percent sign (%) appended to the right; always display two digits to the right of the decimal separator.
ScientificScientific 使用标准科学记数法。Use standard scientific notation.
是/否Yes/No 如果数字为 0,则显示 No;否则显示 Yes。Display No if number is 0; otherwise, display Yes.
True/FalseTrue/False 如果数字为 0,则显示 False;否则显示 TrueDisplay False if number is 0; otherwise, display True.
On/OffOn/Off 如果数字为 0,则显示 Off;否则显示 On。Display Off if number is 0; otherwise, display On.

用户定义的字符串格式User-defined string formats

可以使用以下任意字符为字符串创建格式表达式You can use any of the following characters to create a format expression for strings.

字符Character 说明Description
@ 字符占位符。Character placeholder. 显示字符或空格。Display a character or a space. 如果字符串在格式字符串中的 at (@) 符号位置有一个字符,则显示该字符;否则,将在该位置显示空格。If the string has a character in the position where the at symbol (@) appears in the format string, display it; otherwise, display a space in that position. 占位符从右到左填充,除非格式字符串中有感叹号字符 (!)。Placeholders are filled from right to left unless there is an exclamation point character (!) in the format string.
& 字符占位符。Character placeholder. 显示字符或不显示任何内容。Display a character or nothing. 如果字符串在显示 & 号 (&) 的位置有一个字符,则显示该字符;否则,将不在该位置显示任何内容。If the string has a character in the position where the ampersand (&) appears, display it; otherwise, display nothing. 占位符从右到左填充,除非格式字符串中有感叹号字符 (!)。Placeholders are filled from right to left unless there is an exclamation point character (!) in the format string.
< 强制使用小写形式。Force lowercase. 以小写形式显示所有字符。Display all characters in lowercase format.
> 强制使用大写形式。Force uppercase. 以大写形式显示所有字符。Display all characters in uppercase format.
! 强制从左至右填充占位符。Force left to right fill of placeholders. 默认情况下,将从右至左填充占位符。The default is to fill placeholders from right to left.

用户定义的日期/时间格式User-defined date/time formats

下表标识了可用于创建用户定义的日期/时间格式的字符。The following table identifies characters you can use to create user-defined date/time formats.

字符Character 说明Description
(:) 时间分隔符。Time separator. 在一些区域设置中,可使用其他字符表示时间分隔符。In some locales, other characters may be used to represent the time separator. 在设置时间值格式时,时间分隔符用于分隔小时、分钟和秒。The time separator separates hours, minutes, and seconds when time values are formatted. 在格式化输出中用作时间分隔符的实际字符由您的系统设置决定。The actual character used as the time separator in formatted output is determined by your system settings.
(/) 日期分隔符Date separator. 在部分区域,也可以使用其他字符表示日期分隔符。In some locales, other characters may be used to represent the date separator. 在设置日期值格式时,日期分隔符用于分隔天、月和年。The date separator separates the day, month, and year when date values are formatted. 在格式化输出中用作日期分隔符的实际字符由您的系统设置决定。The actual character used as the date separator in formatted output is determined by your system settings.
cc 按该顺序将日期显示为 ddddd,并将时间显示为 tttttDisplay the date as ddddd and display the time as ttttt, in that order. 如果日期序列号没有小数部分,则仅显示日期信息;如果没有整数部分,则仅显示时间信息。Display only date information if there is no fractional part to the date serial number; display only time information if there is no integer portion.
dd 将日显示为不带前导零的数字 (1–31)。Display the day as a number without a leading zero (1–31).
dddd 将日显示为带前导零的数字 (01–31)。Display the day as a number with a leading zero (01–31).
dddddd 将日显示为缩写形式(日–六)。Display the day as an abbreviation (Sun–Sat). 本地化。Localized.
dddddddd 将日显示为完整名称(星期天–星期六)。Display the day as a full name (Sunday–Saturday). 本地化。Localized.
dddddddddd 将日期显示为完整日期(包括日、月和年),并根据您系统的短日期格式设置进行格式设置。Display the date as a complete date (including day, month, and year), formatted according to your system's short date format setting. 默认短日期格式为 m/d/yyThe default short date format is m/d/yy.
dddddddddddd 将日期序列号显示为完整日期(包括日、月和年),并根据您系统识别的长日期设置进行格式化。Display a date serial number as a complete date (including day, month, and year) formatted according to the long date setting recognized by your system. 默认长日期格式为 mmmm dd, yyyyThe default long date format is mmmm dd, yyyy.
ww 将一周中的某一天显示为数字(1 到 7 分别表示星期天到星期六)。Display the day of the week as a number (1 for Sunday through 7 for Saturday).
wwww 将一年中的一周显示为数字 (1–54)。Display the week of the year as a number (1–54).
mm 将月显示为不带前导零的数字 (1–12)。Display the month as a number without a leading zero (1–12). 如果 m 紧跟 hhh,则显示分钟而不是显示月。If m immediately follows h or hh, the minute rather than the month is displayed.
mmmm 将月显示为带前导零的数字 (01–12)。Display the month as a number with a leading zero (01–12). 如果 m 紧跟 hhh,则显示分钟而不是显示月。If m immediately follows h or hh, the minute rather than the month is displayed.
mmmmmm 将月显示为缩写形式(一–十二)。Display the month as an abbreviation (Jan–Dec). 本地化。Localized.
mmmmmmmm 将月显示为完整月名称(一月–十二月)。Display the month as a full month name (January–December). 本地化。Localized.
qq 将一年中的一个季度显示为数字 (1–4)。Display the quarter of the year as a number (1–4).
yy 将一年中的一天显示为数字 (1–366)。Display the day of the year as a number (1–366).
yyyy 将年显示为 2 位数字 (00–99)。Display the year as a 2-digit number (00–99).
yyyyyyyy 将年显示为 4 位数字 (100–9999)。Display the year as a 4-digit number (100–9999).
hh 将小时显示为不带前导零的数字 (0–23)。Display the hour as a number without a leading zero (0–23).
hhhh 将小时显示为带前导零的数字 (00–23)。Display the hour as a number with a leading zero (00–23).
nn 将分钟显示为不带前导零的数字 (0–59)。Display the minute as a number without a leading zero (0–59).
nnnn 将分钟显示为带前导零的数字 (00–59)。Display the minute as a number with a leading zero (00–59).
ss 将秒显示为不带前导零的数字 (0–59)。Display the second as a number without a leading zero (0–59).
ssss 将秒显示为带前导零的数字 (00–59)。Display the second as a number with a leading zero (00–59).
tttttttttt 将时间显示为完整时间(包括小时、分钟和秒),并使用由您系统识别的时间格式定义的时间分隔符进行格式设置。Display a time as a complete time (including hour, minute, and second), formatted using the time separator defined by the time format recognized by your system. 如果选择前导零选项且时间在 10:00 A.M.A leading zero is displayed if the leading zero option is selected and the time is before 10:00 A.M. 或 P.M 之前,则显示前导零。or P.M. 默认时间格式为 h:mm:ssThe default time format is h:mm:ss.
AM/PMAM/PM 使用 12 小时制,并为中午之前的任意小时显示大写形式的 AM;为中午与 11:59 P.M 之间的任意小时显示大写形式的 PM。Use the 12-hour clock and display an uppercase AM with any hour before noon; display an uppercase PM with any hour between noon and 11:59 P.M.
am/pmam/pm 使用 12 小时制,并为中午之前的任意小时显示小写形式的 AM;为中午与 11:59 P.M 之间的任意小时显示小写形式的 PM。Use the 12-hour clock and display a lowercase AM with any hour before noon; display a lowercase PM with any hour between noon and 11:59 P.M.
A/PA/P 使用 12 小时制,并为中午之前的任意小时显示大写形式的 A;为中午与 11:59 P.M 之间的任意小时显示大写形式的 P。Use the 12-hour clock and display an uppercase A with any hour before noon; display an uppercase P with any hour between noon and 11:59 P.M.
a/pa/p 使用 12 小时制,并为中午之前的任意小时显示小写形式的 A;为中午与 11:59 P.M 之间的任意小时显示小写形式的 P。Use the 12-hour clock and display a lowercase A with any hour before noon; display a lowercase P with any hour between noon and 11:59 P.M.
AMPMAMPM 使用 12 小时制,并为中午之前的任意小时显示您的系统定义的 AM 字符串文本;为中午与 11:59 P.M 之间的任意小时显示您的系统定义的 PM 字符串文本。Use the 12-hour clock and display the AM string literal as defined by your system with any hour before noon; display the PM string literal as defined by your system with any hour between noon and 11:59 P.M. AMPM 可以是大写形式或小写形式,但显示的字符串的大小写形式必须与您的系统设置所定义的字符串匹配。AMPM can be either uppercase or lowercase, but the case of the string displayed matches the string as defined by your system settings. 默认格式为 AM/PM。The default format is AM/PM. 如果系统设置为 24 小时制,则字符串通常设置为零长度字符串。If your system is set to 24-hour clock, the string is typical set to a zero-length string.

用户定义的数字格式User-defined numeric formats

下表标识了可用于创建用户定义的数字格式的字符。The following table identifies characters you can use to create user-defined number formats.

字符Character 说明Description
None 显示不带任何格式的数字。Display the number with no formatting.
(0)(0) 数字占位符。Digit placeholder. 显示一个数字或一个零。Display a digit or a zero. 如果表达式在格式字符串中出现 0 的位置有一个数字,则显示该数字;否则,在该位置显示零。如果数字的位数少于格式表达式中的零的位数(小数的两边),则显示前导或尾随零。If the expression has a digit in the position where the 0 appears in the format string, display it; otherwise, display a zero in that position.If the number has fewer digits than there are zeros (on either side of the decimal) in the format expression, display leading or trailing zeros. 如果数字在格式表达式中的小数分隔符右边具有的位数多于小数分隔符右边的零的数目,则将对该数字进行四舍五入(小数位的数目与零的数目相等)。If the number has more digits to the right of the decimal separator than there are zeros to the right of the decimal separator in the format expression, round the number to as many decimal places as there are zeros. 如果数字在格式表达式中的小数分隔符左边具有的位数多于小数分隔符左边的零的数目,则显示多余的位数而进行修改。If the number has more digits to the left of the decimal separator than there are zeros to the left of the decimal separator in the format expression, display the extra digits without modification.
(#) 数字占位符。Digit placeholder. 显示一个数字或不显示任何内容。Display a digit or nothing. 如果表达式在格式字符串中的显示 # 的位置有一个数字,则显示该数字;否则,不在该位置显示任何内容。If the expression has a digit in the position where the # appears in the format string, display it; otherwise, display nothing in that position. 此符号的工作方式与 0 数字占位符类似,只不过当数字在格式表达式中具有的数位等于或少于小数分隔符两边的 # 字符的数目时,不显示前导零或尾随零。This symbol works like the 0 digit placeholder, except that leading and trailing zeros aren't displayed if the number has the same or fewer digits than there are # characters on either side of the decimal separator in the format expression.
(.) 小数点占位符。Decimal placeholder. 在一些区域设置中,将逗号用作小数分隔符。In some locales, a comma is used as the decimal separator. 小数点占位符决定小数分隔符左边和右边显示的数位。The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. 如果格式表达式只在此符号左边包括数字符号,则小于 1 的数字将以小数分隔符开头。If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. 若要显示随小数一起显示的前导零,请将 0 用作小数分隔符左边的第一个数字占位符。To display a leading zero displayed with fractional numbers, use 0 as the first digit placeholder to the left of the decimal separator. 在格式化的输出中用作小数占位符的实际字符取决于您的系统所识别的数字格式。The actual character used as a decimal placeholder in the formatted output depends on the Number Format recognized by your system.
(%) 百分比占位符。Percentage placeholder. 将表达式乘 100。The expression is multiplied by 100. 百分号 (%) 将插入其在格式字符串中出现的位置。The percent character (%) is inserted in the position where it appears in the format string.
(,) 千位分隔符。Thousand separator. 在部分区域,句点用作千位分隔符。In some locales, a period is used as a thousand separator. 千位分隔符将在小数分隔符左边具有四个或更多位的数字中分隔千位和百位。The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. 如果格式包含由数字占位符(0#)包围的千位分隔符,则将指定千位分隔符的标准用法。Standard use of the thousand separator is specified if the format contains a thousand separator surrounded by digit placeholders (0 or #). 两个相邻的千位分隔符或紧靠小数分隔符(无论是否指定小数)左边的一个千位分隔符意指"将数字除以 1000 来按比例显示数字,并根据需要进行舍入"。Two adjacent thousand separators or a thousand separator immediately to the left of the decimal separator (whether or not a decimal is specified) means "scale the number by dividing it by 1000, rounding as needed." 例如,您可以使用格式字符串"##0,,"将 1 亿表示为 100。For example, you can use the format string "##0,," to represent 100 million as 100. 小于 1 亿的数字将显示为 0。Numbers smaller than 1 million are displayed as 0. 在紧靠小数分隔符左边的位置之外的任何其他位置的两个相邻的千位分隔符将被简单对待,就像指定千位分隔符的用法一样。Two adjacent thousand separators in any position other than immediately to the left of the decimal separator are treated simply as specifying the use of a thousand separator. 在格式化的输出中用作千位分隔符的实际字符取决于您的系统所识别的数字格式。The actual character used as the thousand separator in the formatted output depends on the Number Format recognized by your system.
(:) 时间分隔符。Time separator. 在一些区域设置中,可使用其他字符表示时间分隔符。In some locales, other characters may be used to represent the time separator. 在设置时间值格式时,时间分隔符用于分隔小时、分钟和秒。The time separator separates hours, minutes, and seconds when time values are formatted. 在格式化输出中用作时间分隔符的实际字符由您的系统设置决定。The actual character used as the time separator in formatted output is determined by your system settings.
(/) 日期分隔符Date separator. 在部分区域,也可以使用其他字符表示日期分隔符。In some locales, other characters may be used to represent the date separator. 在设置日期值格式时,日期分隔符用于分隔天、月和年。The date separator separates the day, month, and year when date values are formatted. 在格式化输出中用作日期分隔符的实际字符由您的系统设置决定。The actual character used as the date separator in formatted output is determined by your system settings.
(E- E+ e- e+)(E- E+ e- e+) 科学记数法格式。Scientific format. 如果格式表达式在 E-、E+、e- 或 e+ 的右边至少包括一个数字占位符(0#),则数字以科学记数法格式显示,并且 E 或 e 将插入该数字与其指数之间。If the format expression contains at least one digit placeholder (0 or #) to the right of E-, E+, e-, or e+, the number is displayed in scientific format and E or e is inserted between the number and its exponent. 右边的数字占位符的数目将决定指数中的位数。The number of digit placeholders to the right determines the number of digits in the exponent. 使用 E- 或 e- 可在负指数旁边放置减号。Use E- or e- to place a minus sign next to negative exponents. 使用 E+ 或 e+ 可以在负指数旁边放置减号并在正指数旁边放置加号。Use E+ or e+ to place a minus sign next to negative exponents and a plus sign next to positive exponents.
- + $ ( )- + $ ( ) 显示文本字符。Display a literal character. 若要显示所列字符之外的字符,请在该字符前面加反斜杠 (\) 或将其用双引号括起来 (" ")。To display a character other than one of those listed, precede it with a backslash (\) or enclose it in double quotation marks (" ").
(\) 显示格式字符串中的下一个字符。Display the next character in the format string. 若要将具有特殊含义的字符显示为文本字符,请在该字符前面加上反斜杠 (\)。To display a character that has special meaning as a literal character, precede it with a backslash (\). 反斜杠本身不会显示。The backslash itself isn't displayed. 使用反斜杠与使用双引号将下一个字符括起来的效果相同。Using a backslash is the same as enclosing the next character in double quotation marks. 若要显示反斜杠,请使用双反斜杠 (\\)。To display a backslash, use two backslashes (\\). 不能显示为文字字符的字符示例为日期格式字符和时间格式字符(a、c、d、h、m、n、p、q、s、t、w、y、/ 和 :)、数字格式字符(#、0、%、E、e、逗号和句点)和字符串格式字符(@、&、<、> 和 !)。Examples of characters that can't be displayed as literal characters are the date-formatting and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, /, and :), the numeric-formatting characters (#, 0, %, E, e, comma, and period), and the string-formatting characters (@, &, <, >, and !).
("ABC")("ABC") 显示双引号 (" ") 中的字符。Display the string inside the double quotation marks (" "). 若要在代码中包含 format 格式的字符串,必须使用 Chr( 34) 将文本括起来(34 为双引号 (") 的字符代码)。To include a string in format from within code, you must use Chr(34) to enclose the text (34 is the character code for a quotation mark (")).

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.