Str, Str$ Functions

Named Arguments

No

Syntax

Str(number)

number

Use: Required

Data Type: Numeric Variant

Any numeric expression.

Return Value

A Variant of subtype String (returned by Str) or a String (returned by Str$) representing number.

Description

Converts number from a numeric to a string.

Rules at a Glance

If the return value is positive, the Str function always includes a leading space in the returned string for the sign of number.

Programming Tips and Gotchas

  • Use the LTrim function to remove the leading space that the Str function adds to the start of the returned string.

  • Both the CStr and Format functions have now superseded the Str function. The CStr function doesn't add a leading space for the sign of a positive number. The Format function is internationally aware, being able to recognize decimal delimiters other than the period (.).

See Also

CStr Function, Format Function, LTrim Function

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.