STR$ function

Purpose: STR$ converts a number to a string.


Syntax:

 RetStr$ = STR$(Number[,NoSpace%])

Parameters:

  • Number Integer or floating point literal or variable.
  • NoSpace%[OPTIONAL] The default no argument or 0 indicates that a space is prepended to the returned string if the Number is positive. If NoSpace% is 1 then the space will not be prepended to the RetStr$.

Return Value:

  • RetStr$, the return value, is a string converted from the Number parameter argument.

Remarks:

By default, a space is prepended to the returned string if the number is positive and the optional NoSpace% parameter is empty or 0. This space is the location for the sign part of the number. When the Number argument is a negative number, a minus sign will be there.

Example:


  DIM RetStr$
  
  RetStr$ = STR$(3.14159)
  
  PRINT DQ$ & RetStr$ & DQ$
  
  RetStr$ = STR$(-3.14159)
  
  PRINT DQ$ & RetStr$ & DQ$

  RetStr$ = STR$(3.14159, 1)
  
  PRINT DQ$ & RetStr$ & DQ$

Result:


" 3.14159" 
"-3.14159" 
"3.14159"

BCX Console Sample Programs using STR$ function.

S04.bas, S10.bas, S19.bas, S24.bas, S54.bas, S70.bas, S89.bas, S92.bas, S107.bas