Re: TI85 Concatenating numbers/Numbers -> Strng


[Prev][Next][Index][Thread]

Re: TI85 Concatenating numbers/Numbers -> Strng



OK, here's how to make a number into a string.


If you  have the variable A, which contains the integer 167 (or any
integer), and you want "167" in a string, follow these steps:


make a varialbe called ST  for example and store a singe character in
it. You'll see why later








first, use mod(A, 10) to "pluck off" the least significant digit of the
value in A, and store it ina variabe like B. B will contain a value from
0 to 9. the mod function returns the remainder after doing an integer
division. That remainder will become a string in the nest step.


Next use the Sub function to put that digit in your output string. here
id the full command
sub("0123456789",B+1,1)+ST -> ST


your string now has one didgit of your number in it. If ST has nothing
in it when you try to execute this, the program will stop. That's why
you need ST initialized with a random character of your choosing. Ti85
string functions aren't too good.


Next, you need to set up A so that you can use a loop to get the other
digits. What I usually do for readability is use the following expression


(A-B)/10 ->A


this expression shortens 167 to 16. It will strip off the last digit of
any integer.








now just put all this in a while loop (or a repeat loop depending on if
A will be 0 when you call this routine)  that terminates when A is 0
,and you have a string.  One more thing:  you have to remove that
character at the end of the string. this is the best way:


sub(ST,1,length ST-1) -> ST


Make sure ST contains TWO charaters before you shorten ST or you'll
probably get youself in trouble.


That should do it. You can just tinker with the algorithm to make
strings out of negative numbers or numbers with a decimal point. I
suppose I can post actual code (with speed optimizations) if nessecary.
But you learn more by doing it yourself...


-Jonathan


References: