Name
Str Function
Class
Microsoft.VisualBasic.Conversion
Syntax
Str(number)-
number Use: Required
Data Type: Numeric
Any valid numeric expression or expression capable of conversion to a number
Return Value
A String representation of number
Description
Converts number from a numeric to a string
Rules at a Glance
If the conversion of
numberto a string cannot be made, an InvalidCastException error occurs. To prevent this, you can check the value ofnumberby passing it to theIsNumericfunction before callingStr.If
numberis not a numeric value or is not capable of conversion to a number (so that it can in turn be converted to a string), an InvalidCastException exception occurs.If the return value is positive, the
Strfunction always includes a leading space in the returned string for the sign ofnumber.
Programming Tips and Gotchas
Use the
LTrimfunction to remove the leading space that theStrfunction adds to the start of the returned string.Both the
CStrandFormatfunctions have now superceded theStrfunction. TheCStrfunction does not add a leading space for the sign of a positive number. Both theCStrand theFormatfunctions are internationally aware, able to recognize decimal delimiters other than the period (.).
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access