Is there any way, in a pure TI basic program, to convert a real number into a string?
http://tibasicdev.wikidot.com/number-to-string
TheStorm wrote:
Yay, ability to read first Google result for a search! If only more users had these skills.
On the other hand, I find this method slow. There's an even better method. See this post:
http://tibasicdev.wikidot.com/forum/t-593558/fastest-way-to-turn-a-number-into-a-string

Here's a Zeda Quote:
Quote:

Depending on what form the number will be in, you could definitely make some faster codes. If it is only ever a positive integer, for example, you could do something like this:

;C is the number to convert
"0→Str1
Repeat not(C
sub("0123456789",1+10fPart(.1C),1)+Str1→Str1
iPart(.1C→C
End
sub(Str1,1,length(Str1)-1
KermMartian wrote:
TheStorm wrote:
Yay, ability to read first Google result for a search! If only more users had these skills.


It seems that everytime someone says that, i actually did search. My google skills must be bad. :-\
If you want to do it with Hybrid BASIC, there's an even faster method to convert reals to strings:

http://dcs.cemetech.net/index.php/BasicLibs:NumToString
If you have BatLib, for Hybrid, you can use dim(110,#
My goal is to do it with no dependencies. And, yes I did do a google search and turned up the LinReg version, but it was slow so I thought I'd ask.

Will Roguebantha's pasted routine work with all real numbers? Zero, positive, and negative? Integers and fractions? Or will I need to fix it up a bit?
ACagliano wrote:
My goal is to do it with no dependencies. And, yes I did do a google search and turned up the LinReg version, but it was slow so I thought I'd ask.

Will Roguebantha's pasted routine work with all real numbers? Zero, positive, and negative? Integers and fractions? Or will I need to fix it up a bit?
Zeda wrote:
If it is only ever a positive integer...
Please engage your brain.
Oh. I didn't even see that...

Edit: realized I only need positive anyway. But I do need decimal support.
ACagliano wrote:
Oh. I didn't even see that...

Edit: realized I only need positive anyway. But I do need decimal support.
With a bit of simple BASIC string manipulation you should be able to expand it to support decimals.
I'll work on it. In the meantime, I'll release it with the LinReg method. Now...to get my computer back from the Apple Store...
If you tried the linreg solution and it was too slow why didn't you say so in the first post? Then I wouldn't have bothered to take the time to post it since we would have already known you tried it.
Sorry. I had literally 30 seconds to make the post.


Edit: I figured it out... in psuedocode.

1-->dim(L1)
iPart(number) --> E
If int(number) /= number:Then
fPart(number) --> F
Repeat int(F)=F
Fx10-->F
End
dim(L1) + 1 --> dim(L1)
F-->L1(2)
End

For (A, 1, dim(L1))
//do the code that only works for positive integers
If dim(L1)-A > 0:Then
String + "." --> String
End
End
How to do it with decimal support. Use fpart to seperate the two, and concatenate them together at the end.
Ninja'd
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement