Re: Variable to string on TI83


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

Re: Variable to string on TI83



On Wed, 16 Jul 1997, Bob Smithingford <ifjewa@LKJFLSD.COM> wrote:

> Does anyone know how to store the contents of a variable into a string? I
> can't seem to get it. For example, I want the contents of the variable x to
> be stored in String 1. Any help you be appretiated.
>
> Dan
> E-mail -  plug@cyberstreet.com

TI should have provided a built-in command to do this.

Here are two different number-to-string conversion programs I have
written. They may not be exactly what you need, but they should
give you an idea how to proceed.

The first is only for integers from 0 to 999, although it could be
adapted to other situations. It puts leading spaces before numbers
with fewer than three digits. (Lines 3 through 5 put the units digit
into C, the tens digit into B, and the hundreds digit into A.)

------------------------------------------------------------------

PROGRAM NUMTOSTR.83p

"0123456789 " -> Str9
Prompt X
10fPart(X/10) -> C
10fPart((X-C)/100) -> B
(X-10B-C)/100 -> A
If A=0:10 -> A
If A=10 and B=0:10 -> B
sub(Str9,A+1,1)+sub(Str9,B+1,1)+sub(Str9,C+1,1) -> Str1
Disp "/"+Str1+"/"

------------------------------------------------------------------

The second is more versatile: I figured out a roundabout way to
use the TI-83's built-in number-printing routine to put a number
into a string instead of for printing.

The program uses the "LinReg(" command to put an equation
containing the number into Y1, and then uses the "Equ>String("
command to copy the equation Y1 into the string Str1, and then
extracts the number. I think it will work for any number. Note
that the version below rounds the number to three decimal places
(see the fourth line).

------------------------------------------------------------------

PROGRAM NUM2STR.83p

Prompt X
{1,2} -> L1
{X,X} -> L2
round(L2,3) -> L2
LinReg(ax+b) L1,L2,Y1

Equ>String(Y1,Str1)
sub(Str1,4,length(Str1)-3) -> Str1
DelVar Y1
Disp "/"+Str1+"/"

------------------------------------------------------------------
Evan Romer                                   Susquehanna Valley HS
sv_golden@SUNYbroome.edu                          Conklin NY 13748