## TI-83 CStr: Convert numbers to strings

### Is a separate program necessary?

Graphing calculators do not allow you to calculate a number and display it on the same line as a string value. The function below simply takes any number and converts it to a string value. I have seen several examples online that accomplish a similar function, but I have never seen one that is able to handle all the types of numbers this program can handle. The program below will convert negative numbers, decimal numbers, numbers with trailing zeros as place holders, decimals with leading zeros, and just about anything else you throw at it.

### My Program’s Flaw

I would like to point out one bug/flaw in the program: If you enter a number like 6.0, it will only return a 6. Therefore, significant figures may be lost in the conversion process, but in general for the purposes of most people significant figures are not relevant.

One last note: this is not a tutorial — it is simply showing you a program. I have every intention of making a tutorial for this program to explain everything that’s going on…but until then you’ll have to settle for an uncommented program.

### Syntax

(numerical value) -> A
pgrmCSTR
Str0 ;Your numerical value returned in string format

If you name this program pgrmCSTR, all you have to do is store a numerical value in variable A, call pgrmCSTR, then use Str0 as the string equivalent to your numerical value.

### The Code

:” “->Str0
:0->L6(1)
:A->L6(2)
:0->L6(3)
:
:If A<0
:Then
:1->L6(3)
:abs(A)->A
:End
:
:If A<1
:Then
:While A<1
:10A->A
:L6(1)-1->L6(1)
:End
:End
:
:If A>=10
:Then
:While A>=10
:A/10->A
:L6(1)+1->L6(1)
:End
:End
:
:While A‡0
:Str0+sub(“01234567890″,iPart(A)+1,1)->Str0
:fPart(A)->A
:10A->A
:End
:
:sub(Str0,2,length(Str0)-1)->Str0
:
:If L6(1)=0
:Then
:length(Str0)->L6(4)
:sub(Str0,1,1)->Str9
:If L6(4)‡1
:Then
:sub(Str0,2,L6(4)-1)->Str8
:Str9+”.”+Str8->Str0
:Else
:” “->Str8
:End
:End
:
:If L6(1)<0
:Then
:For(L6(5),L6(1)+1,0)
:”0″+Str0->Str0
:End
:length(Str0)->L6(4)
:sub(Str0,2,L6(4)-1)->Str8
:”0.”+Str8->Str0
:End
:
:If L6(1)>0
:Then
:If length(Str0)-1
:Then
:
:For(X,0,L6(1)-length(Str0))
:Str0+”0″->Str0
:End
:End
:
:If fPart(L6(2))‡0
:Then
:sub(Str0,1,L6(1)+1)->Str9
:length(Str0)-length(Str9)-1->L6(4)
:sub(Str0,L6(1)+2,L6(4)+1)->Str8
:Str9+”.”+Str8->Str0
:End
:End
:
:If L6(3)=1
:Then
:”-“+Str0->Str0
:End