# Variables To Strings?

4 replies to this topic

### #1 bennyboy8888

bennyboy8888

Newbie

• Members
• 4 posts

• Calculators:
fx-9860 AU Plus

Posted 15 June 2014 - 01:23 PM

Very simply, I am trying to get the value of a variable and then place it in the middle of a string.
i.e.
```1->List 1[1]
"string before variable "+List 1[1]+" string after variable"->Str 1
Locate 1,1,Str 1
```
Would display
`string before variable 1 string after variable`
starting at the top right corner.

I know you can put functions into strings using the fn command and the Exp>Str( command but using the example above, it would read
`List 1[1]`
Ideas?
Cheers

Edited by bennyboy8888, 15 June 2014 - 01:35 PM.

### #2 bennyboy8888

bennyboy8888

Newbie

• Members
• 4 posts

• Calculators:
fx-9860 AU Plus

Posted 16 June 2014 - 09:28 AM

Found an answer. Not sure if it's the best (probably not) but its better than nothing.
Limitations, doesn't work with decimals (not a big deal for my purposes), doesn't work with imaginary numbers.
```135->A //A stores the numbers that you want to convert. 135 is used as an example

0->C //Clears value of C
If A<0 //Checks if A is less than 0
Then
1->C //Flags it as a negative number so that the negative sign can be added after
Abs A->A //Potentially not required but it made sense to me to put it in
EndIf

If A=0 //Checks if A is equal to 0
Then
"0"->Str 2 //Defines the string as 0
Goto 1 //Skips the rest of the program as it is irrelevant
EndIf

""->Str 2 //Clears the string, just in case
Int (log A)->X //Returns the number of digits in the number -1

0->N //Loop variable
While N<=X
A Rmdr 10->B //Dividing by ten gives the right most digit as the remainder so dividing A/10 would give the value 5 for the first iteration given the input shown above
Int (A/10)->A //Shifts the number to the right getting rid of the right most number. With the input above, the first iteration would result in A being redefined as 13

If B=0 //Checks the value of B
Then
"0"+Str 2->Str 2 //Assigns the value of B to the string
EndIf

StrMid("0123456789", B+1, 1)+Str 2->Str 2 //Adds the value of B to the string (Credit to somebody1234)

Isz N //Adds 1 to N
WhileEnd

If C=1 //Checks if A was flagged as a negative number
Then
"-"+Str 2->Str 2 //Adds a negative sign at the front of the string
IfEnd

Lbl 1 //Only used in the case where A=0
```

Feel free to suggest changes, or suggest a better alternative.

Edited by bennyboy8888, 18 August 2014 - 01:53 AM.

### #3 somebody1234

somebody1234

• Members
• 51 posts

• Calculators:
Casio fxcg10
Casio fx-9860GII

Posted 18 August 2014 - 01:08 AM

You can use
`StrMid("0123456789", B+1, 1)+Str 2->Str 2`
as a shorter alternative.

EDIT: You can also use something like
`For 1+Int log N->I To 1 Step -1`
for the loop and also the
```If B=0
Then
"0"+Str 2->Str 2EndIf
```
is not needed. (Also, you wrote EndIf instead of IfEnd)

Edited by somebody1234, 18 August 2014 - 06:17 AM.

• MicroPro likes this

### #4 bennyboy8888

bennyboy8888

Newbie

• Members
• 4 posts

• Calculators:
fx-9860 AU Plus

Posted 18 August 2014 - 01:55 AM

Changed it, much more efficient way of doing that section. Thanks!

### #5 somebody1234

somebody1234

• Members
• 51 posts

• Calculators:
Casio fxcg10
Casio fx-9860GII

Posted 18 August 2014 - 06:20 AM

I found this code here:
```?→N // your number
If N<0
"-"→Str 1
Abs N→N
For 1+Int log N→I To 1 Step -1
Str 1+StrMid("0123456789",1+Int (10Frac (N/10^I)),1)→Str 1
Next```

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users