|
Topic: DMD0028 STR2REAL - Convert String to Real |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Convert String to Real (STR2REAL) instruction is used to convert the contents of the specified input string from ASCII text to a Real (floating point) value. The input 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 value 12.5.
Another example, STR2REAL will convert a string that contains the characters "6.02E+23" to the value 6.02E+23.
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters:Note: Use the F9 key (Element Browser) or Down-Arrow key (Auto-Complete) at any time to see a complete list of the memory locations that are valid in the current field of the instruction.
Input 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 input 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 - designates where to store the converted real value. This can be writable numeric location.
Index Where Stopped - if enabled, this designates a location that will contain the offset into the Input 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 of the Convert String to Real instruction will only display 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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Related Topics:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rung Example:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||