11 - 384 11 - 384
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
STR$
Function
STRing$
• Converts a value to a character string, assuming the value is given as a decimal number.
STR$(<numeric expression>)
Syntax
numeric expression
• • • •
Specify the value to be converted into a character
string.
Examples
A$=STR$(-1.602)
• • • •
Converts the value -1.602 to the string "-1.602."
B$=STR$(3.12E08)
• • • •
Converts the value 3.12E08 to the string
" 3.12E08."
Description
• The STR$ function returns the value in <numeric expression> as a character string
expression of a decimal number. Note that it is not allowed to specify data other than
numeric values and variables. All types of numeric values are valid for specification as the
value of <numeric expression>, such as real numbers (double-precision and single-
precision) and floating points.
• The length of the character string returned is equal to the number of digits of the value plus
one character representing the sign. If the value is positive, the sign character becomes
blank.
• If the number of digits of the specified value exceeds 16 digits when a double-precision
real number is specified, or 6 digits when a single-precision real number is specified, the
value is treated in exponential format.
• The VAL function has the opposite functionality of the STR$ function.
In addition, the OCT$ and HEX$ functions convert integer data to octal or hexadecimal
strings, respectively, and return them.
Program Example
10 ' This program converts numeric values to character strings
20 A=123
:
' Defines numeric values
30 B=456
40 C=1.07
50 A$=STR$(A)
:
' Converts into character strings
60 B$=STR$(B)
70 C$=STR$(C)
80 PRINT "A =";A
:
' Displays the results
90 PRINT "B =";B
100 PRINT "C =";C
110 PRINT "A+B =";A+B
120 PRINT "A$+B$=";A$+B$
130 PRINT "C$ =";C$
140 END