Converting A Text String Into A Numerical Value
Suppose you have two text strings, each expressing a numerical value:
Set a = “17”
Set b = “852”
And you wanted to write a program that would simply add those two values together (to produce
869). If you tried to do it this way:
Set a = “17”
Set b = “852”
Set sum = a + b //WRONG!!!
Display sum
the program would display:
17852. (Remember, a plus sign [ + ] between two text strings means concatenation.)The system library's "ttoi" function (text to integer) will convert a string of text digits into their corresponding numerical equivalent. For example, the statement:
Set x = ttoi("357")
produces exactly the same result as the statement:
Set x = 357
[The system library also contains several other very useful conversion functions such as: "ttof" (which converts from text to floating point), etc.]
Therefore the correct way to write our program would be:
Set a = “17”
Set b = “852”
Set sum = ttoi(a) + ttoi(b)
Display sum