Str 函数

返回数字的“变量”(“字符串”)表示。

语法

str (number)

所需的 number参数是包含任何有效数值表达式Long

备注

数字转换为字符串时, 始终为数字 的符号保留前导空格。 如果数字 为正,则返回的字符串包含前导空格,并隐含加号。

使用 Format 函数转换要格式化为日期、时间或货币或其他用户定义的格式的数值。 不同于“Str”,“格式”函数不包括用于数字 的符号的前导空格。

注意

Str 函数仅将 ( 点识别为有效的小数分隔符) 。 When different decimal separators may be used (for example, in international applications), use CStr to convert a number to a string.

示例

This example uses the Str function to return a string representation of a number. When a number is converted to a string, a leading space is always reserved for its sign.

Dim MyString
MyString = Str(459)    ' Returns " 459".
MyString = Str(-459.65)    ' Returns "-459.65".
MyString = Str(459.001)    ' Returns " 459.001".

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。