Topic: DMD0028 STR2REAL - Convert String to Real |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Convert String to Real (STR2REAL) instruction is used to convert the contents of the specified string from ASCII text to a Real (floating point) value. The string can contain text the traditional floating point form (number with a decimal point: xx.yy), the exponential form (number with E: x.xEy), or simple decimal form (x.xxxEyy).
For example, STR2REAL will convert a string that contains the characters "12.5" to the Real value 12.5. Another example, STR2REAL will convert a string that contains the characters "6.02E+23" to the Real value 6.02E+23.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters:Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.
String- the String that contains the data to be converted. This can be any of the system-defined Short Strings (SS Block), or system-defined Long Strings (SL Block), or readable String element.
Valid input characters are '0' - '9' and the ".", "E", "e", "+", and "-"
If an invalid character is found the valid characters up to that point will be converted and the remaining characters ignored. For example, if the string contains the text "1234x5678", the conversion will result in the value 1234.0. See the optional parameter Index where Stopped for information on how to handle this condition.
Because we are dealing with floating point numbers, the following three special cases must be considered : if the conversion results is positive or negative infinity, the result will be +infinity or -infinity respectively. If the conversion results in an invalid number, the result will be NotANum (not a number).
Numeric Output - specifies where to store the converted Real value. This can be writable numeric location.
Index Where Stopped - if enabled, this specifies a location that will contain the offset into the String after valid digits are found where the conversion process stopped. The following examples display the conditions that will cause the conversion to stop and set the Index Where Stopped value.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Status Display:
The Status display will only show as many of the characters of the String as will fit within the borders of the instruction, typically this is about 50 characters.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
See Also:
SEG
- Hex / BCD to 7 Segment Display
STR2REAL - Convert String to Real
STR2INT - Convert String to Integer
STRCASE - Convert String to UPPER / lower Case
STRCOPYR - Copy a Range of Strings
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Related Topics:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rung Example:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|