Is there any way, in a pure TI basic program, to convert a real number into a string?
"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown
"If you've done something right no one will know that you've done anything at all" -Futurama
"Have a nice day, or not, the choice is yours." Tom Steiner
<Michael_V> or create a Borg collective and call it The 83+
<Michael_V> Lower your slide cases and prepare to be silent linked. Memory clears are futile.
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:
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
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. :-\
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
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
http://dcs.cemetech.net/index.php/BasicLibs:NumToString
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?
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?
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.
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. Edit: realized I only need positive anyway. But I do need decimal support.
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.
"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown
"If you've done something right no one will know that you've done anything at all" -Futurama
"Have a nice day, or not, the choice is yours." Tom Steiner
<Michael_V> or create a Borg collective and call it The 83+
<Michael_V> Lower your slide cases and prepare to be silent linked. Memory clears are futile.
- ACagliano
- Guru-in-Training (Posts: 2001)
- 05 Dec 2012 06:18:51 pm
- Last edited by ACagliano on 05 Dec 2012 07:18:41 pm; edited 1 time in total
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
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
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
» 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
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