Conversion.Str(Object) 方法

定义

返回数字的 String 表示形式。Returns a String representation of a number.

public:
 static System::String ^ Str(System::Object ^ Number);
public static string Str (object Number);
static member Str : obj -> string
Public Function Str (Number As Object) As String

参数

Number
Object

必需。Required. 包含任何有效的数值表达式的 ObjectAn Object containing any valid numeric expression.

返回

String

数字的 String 表示形式。A String representation of a number.

例外

未指定 NumberNumber is not specified.

Number 不是 Numeric 类型。Number is not a numeric type.

示例

此示例使用 Str 函数返回 String 数字的表示形式。This example uses the Str function to return a String representation of a number. 当正数转换为字符串时,将始终为其符号保留前导空格。When a positive number is converted to a string, a leading space is always reserved for its sign.

Dim testString As String
' Returns " 459".
testString = Str(459)
' Returns "-459.65".
testString = Str(-459.65)
' Returns " 459.001".
testString = Str(459.001)

注解

当数字转换为字符串时,将始终为的符号保留前导空格 NumberWhen numbers are converted to strings, a leading space is always reserved for the sign of Number. 如果 Number 为正,则返回的字符串将包含前导空格,并暗含正负号。If Number is positive, the returned string contains a leading space, and the plus sign is implied. 负数将包括减号 ( ) ,无前导空格。A negative number will include the minus sign (-) and no leading space.

使用 Format 函数可以将要设置格式的数值转换为日期、时间、货币或其他用户定义格式。Use the Format function to convert numeric values you want formatted as dates, times, or currency or in other user-defined formats. Str 函数不同, Format 函数不包含用于的符号的前导空格 NumberUnlike the Str function, the Format function does not include a leading space for the sign of Number.

备注

Str函数仅识别 .) 为有效小数点分隔符 (的时间段。The Str function recognizes only the period (.) as a valid decimal separator. 例如,如果使用不同的小数点分隔符 (例如,在 "国际化应用程序") 中,使用 CStrFormat 函数将数字转换为字符串。If different decimal separators are used (for example, in international applications), use the CStr or Format functions to convert a number to a string. 若要获取特定区域性中的数字的字符串表示形式,请使用数字的 ToString(IFormatProvider) 方法。To get the string representation of a number in a particular culture, use the number's ToString(IFormatProvider) method. 例如,在将 ToString 类型的值转换 Double 为字符串时使用。For example, use ToString when converting a value of type Double to a string.

适用于

另请参阅