STR$ (x#)           where x# = float
Purpose

When the operand x# is a floating-point data, STR$(x#) will return the string representing the data as either “regular” floating format such as xxx.yyyyy or in scientific notation such as + x.xxxxxxxE+nn, depending on the range of values x# falls into. The following criteria can be used to predict the format of the string that STR$(x#) will return:

Value range of x#

Format

Example

0.0001 < |x#| < 1.0

+0.ffffffff
1 decimal digit and 7
fractional digits.
+0.0012345
-0.4560000
+0.0920000

1.0 < |x#| < 1.0 x107

+ddd.fffff
n decimal digit and (8-n) fractional digits
+123.45600
+90014.016
-55.678000

|x#| > 1.0 x107
|x#| < 0.0001 

+d.fffffffE+nn
1 decimal digit and 7 fractional digits. 2 exponent digits
+2.5670000E+08
-1.3456000E-04
+7.3300000E-09

Notice that in all formats, number of decimal digit+number of fractional digit = 8. In particular, the scientific notation format only uses the following format:

+ x.xxxxxxxE+nn

i.e. the returned string will always start with a sign, then a single decimal digit followed by 7 fractional digits, an E and then the sign of the exponent, followed by the two digit exponents. The length of the returned string is always14 characters when it returns in scientific notation.

Eg. +1.2345000E+10, -9.8763475E-05

This function will return variable significant digit based on the value it evaluated. For fixed number of significant digit, please refer to the next command STR$(x#, w)

Example A$ = STR$(0.000012345) => A$ = +1.2344999E-05
Comments A$ did not get the string “+1.2345000E-05” as expected because this number cannot be precisely represented by the IEEE single precision format and therefore it is approximated by its closest number +1.2344999E-05.

backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual