Str Procedure

Returns the string representation of a number based on the predefined radix.

Syntax

[ s = ] Str ( pNumber [, lBase] )

The Str procedure syntax has the following parts:

Name

Type

Description

s

String

The converted number

pNumber

Val Any

A number to be converted to a string

lBase

Val Long

Radix to be used in conversion (2-36 or 0). The default value is 10.

Comments

Str is used to convert numbers to a string.

The lBase can be a number in the range 2 to 36 or 0. If 0 is used, lBase is assumed to be 10.

if lBase is 10 and the pNumber  is negative, the first character is minus (-). Otherwise, pNumber  is assumed to be unsigned in the range of Long type value.

For floating point numbers the Str function will convert the number to a string as follows:

        Signed values are displayed in f or E format (see below, similar to C language sprintf with %G), whichever is more compact for the given value and precision. If you need different precision that what is provided with this function, use the Format function instead.

        The E format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it. The E format has the form [ – ]d.dddd E [sign]dd[d] where d is one decimal digit, dddd is one or more decimal digits, dd[d] is two or three decimal digits depending on the output format and size of the exponent, and sign is + or –.

        The f format has the form [ – ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.

Use the Format function to control the format of the converted number.

If the pNumber  does contain a number or a string that can be converted to a number, the return string is an empty string. If pNumber contains a Variant data type witha VT_ERROR, the return will be a string in the format "Error 0x%X" where X is an hexadecimal number with the error.

Example

 

i = 0xFF

s = Str(i, 10)          ! s = "255"

i = 0xFF

s = Str(i, 2)           ! s = "11111111"

d = 1234.5678

s = Str(d)              ! s = "1234.57"

f = -1234E+34

s = Str(f, 10)          ! s = "-1.234E+37"

ddw = 0xFFFFFFFF        ! DDWord

s = Str(ddw, 2)         ! s = "11111111111111111111111111111111"

dl = -9876543210        ! DLong

s = Str(dl)             ! s = "-9876543210"

s = Str("1234")         ! s = "1234"

s = Str(00123E+0034, 0) ! s = "1.23E+036" , default base

s = Str("ABC")          ! s = ""  

See Also

Chr, Format, Val