STR
(One intermediate revision by one user not shown) | |||
Line 9: | Line 9: | ||
= <span class="f_Header">Syntax</span> = | = <span class="f_Header">Syntax</span> = | ||
− | var = <span class="f_Syntax">STR</span>( x) | + | var = <span class="f_Syntax">STR</span>( x [,digits]) |
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
Line 16: | Line 16: | ||
= <span class="f_Header">Remarks</span> = | = <span class="f_Header">Remarks</span> = | ||
− | <div style="padding: 0px; margin: 0px 0px 0px 4px;"> | + | <div style="padding: 0px; margin: 0px 0px 0px 4px;"><div style="font-size: 13.3333330154419px; padding: 0px; margin: 0px 0px 0px 4px;"> |
{| width="487" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | {| width="487" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | ||
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
− | | valign="top" width="14%" style="width: | + | | valign="top" width="14%" style="width: 65px; border: 1px solid rgb(0, 0, 0);" | |
var | var | ||
− | | valign="top" width=" | + | | valign="top" width="121%" style="width: 413px; border: 1px solid rgb(0, 0, 0);" | |
A string variable. | A string variable. | ||
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
− | | valign="top" width="14%" style="width: | + | | valign="top" width="14%" style="width: 65px; border: 1px solid rgb(0, 0, 0);" | |
X | X | ||
− | | valign="top" width=" | + | | valign="top" width="121%" style="width: 413px; border: 1px solid rgb(0, 0, 0);" | |
A numeric variable. | A numeric variable. | ||
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
− | | valign="top" width="14%" style="width: | + | | valign="top" width="14%" style="width: 65px; border: 1px solid rgb(0, 0, 0);" | |
digits | digits | ||
− | | valign="top" width=" | + | | valign="top" width="121%" style="width: 413px; border: 1px solid rgb(0, 0, 0);" | |
− | An options parameter, only allowed for doubles. It specifies how many digits after the comma/point are used. | + | An options parameter, only allowed for singles and doubles. |
+ | |||
+ | It specifies how many digits after the comma/point are used. | ||
+ | |||
+ | | ||
+ | |||
+ | When using with a single, you need to use : | ||
+ | |||
+ | [[CONFIG_SINGLE|CONFIG SINGLE=SCIENTIFIC]] | ||
|} | |} | ||
+ | </div> | ||
+ | <span style="font-family: Arial;"> </span> | ||
</div> | </div> | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> |
Latest revision as of 20:19, 15 June 2015
Contents |
Action
Returns a string representation of a number.
Syntax
var = STR( x [,digits])
Remarks
var |
A string variable. |
X |
A numeric variable. |
digits |
An options parameter, only allowed for singles and doubles. It specifies how many digits after the comma/point are used.
When using with a single, you need to use : |
The string must be big enough to store the result. So if you have a string like this : Dim S as string * 4, and you use it on a single with the value 0.00000001 then there is not enough space in the string to hold the result. Strings that are assigned with Str() should be dimmed 16 characters long.
You do not need to convert a variable into a string before you print it.
When you use PRINT var, then you will get the same result as when you convert the numeric variable into a string, and print that string.
The PRINT routine will convert the numeric variable into a string before it gets printed to the serial port.
As the integer conversion routines can convert byte, integer, word and longs into a string it also means some code overhead when you do not use longs. You can include the alternative library named mcsbyte.lbx then. This library can only print bytes. There is also a library for printing integers and words only. This library is named mcsbyteint.
When you use these libs to print a long you will get an error message.
See also
VAL , HEX , HEXVAL , MCSBYTE , BIN , STR2DIGITS
Difference with VB
In VB STR() returns a string with a leading space. BASCOM does not return a leading space.
Example
Dim A As Byte , S As String * 10 A = 123 S = Str(a) Print S ' 123 'when you use print a, you will get the same result. 'but a string can also be manipulated with the string routines. End
Languages | English • Deutsch |
---|