ReadyBASIC
BASIC Language Reference Manual > Command and Function Reference >

STR$ Function

Summary

Converts a numeric value into a string representation of the numeric value.

Syntax

STR$(numeric expression)

Remarks and Examples

Given a numeric value, the STR$ function returns a string containing the numeric value.

If the numeric value is an integer, the string representation will not contain a decimal point. If the numeric value is a floating-point value, the string representation will contain a decimal point.

For example, STR$(45) will return the string "45". STR$(53.0) will return the string "53.0". STR$(7.0001000) will return the string "7.0001".

Sample program:

10 INPUT "Please enter an integer: ", N%
20 A$ = STR$(N%)
30 PRINT "The number "; N% ;" has "; LEN(A$); " digits"
40 PRINT "The first digit of "; N%; " is "; LEFT$(A$, 1)
RUN
Please enter an integer: 567
The number 567 has 3 digits
The first digit of 567 is 5

To convert a string into a numeric value, use the VAL function.

Note: Extremely large or small floating-point values may be rendered using scientific notation. For example, STR$(0.0000000000067) will return the string "6.7E-12". VAL and STR$ support scientific notation, but scientific notation is not yet supported in numeric expressions in program listings. This feature will be added in a later version of ReadyBASIC.




Copyright 2006-2008, Kevin Matz, All Rights Reserved.