Re: TIB: Real number to string


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

Re: TIB: Real number to string




I tested it, and it works.  Two slight errors in my typing:  "If X=M+1" should be "If
Z=M+1", and "Part(Y) -> X" should be "iPart(Y) -> X".

Eric Tollefson
CmdrERT01@yahoo.com

Eric Tollefson wrote:

> That's what I was referring to.  You could make the code look something like this:
>
> (Converts a number X to a string Str1 with N decimal places, where X is <= 99999)
>
> Prompt X, N
> (X>9999)+(X>999)+(X>99)+(X>9)+(X>=1) -> M
> X/10^(M-1) -> Y
> Part(Y) -> X
> sub("0123456789",X+1,1) -> Str1
> Y-X -> Y
> 10Y -> Y
> For(Z, 2, M+N
> If X=M+1
> Str1+"." -> Str1
> iPart(Y) -> X
> Str1+sub("0123456789",X+1,1) -> Str1
> Y-X -> Y
> 10Y -> Y
> End
> Disp Str1
>
> That should work right.  I'll have to punch it into my calc to test it, though.
> (Btw, that's 83(+) code)
>
> Eric Tollefson
> CmdrERT01@yahoo.com
>
> Lloyd Hugh Allen wrote:
>
> > Why not use modular arithmetic to separate out the particular digit you
> > care about? To isolate the "tenths" digit, multiply your number by 10,
> > truncate it, and then mod it by ten. Then I assume that the result can be
> > sent to the routine below. Place value was a HUGE advancement in the
> > development of mathematics. Please note that the routine proposed above and
> > left as an exercise from the reader can be put in a loop to extract N
> > digits from the original number efficiently (and without a lot of extra code).
> >
> > The question is: if pi base ten is 3.14159...etcetc..., what is ten base pi?
> >
> > At 21:02 16-09-2000 EDT, you wrote:
> > >
> > >At any rate, it is MUCH faster and smaller than using If Then groups.
> > >But think of it this way, you'd be in trouble if you wanted to do this with
> > >decimal places and IF Then as well.  You'd need a seperate IF Then for every
> > >tenth, going from 0.0 to 9.9 (100 If Then groups)! But I do see what you are
> > >getting at.  The only solution is to optimise optimise optimise...
> > >
> > >
> > >>From: Eric Tollefson <CmdrERT01@yahoo.com>
> > >>Reply-To: ti-basic@lists.ticalc.org
> > >>To: ti-basic@lists.ticalc.org
> > >>Subject: Re: TIB: Real number to string
> > >>Date: Sat, 16 Sep 2000 00:38:06 -0400
> > >>
> > >>
> > >>Okay, I'll admit you've got me there.  But, you're still in trouble if you
> > >>want
> > >>anything besides a whole number.  I suppose you could add in more of those
> > >>and
> > >>use some fPart commands to add decimal places, but it would be large and
> > >>awkward
> > >>to code for anything beyond maybe 1 or 2 decimal places.  My point was that
> > >>there is no built-in command to perform this task.  Although it would make
> > >>life
> > >>peachy if there was.
> > >>
> > >>Eric Tollefson
> > >>CmdrERT01@yahoo.com
> > >>
> > >>"C.J. Wallace" wrote:
> > >>
> > >> > >I'll assume that that's for the 89, since I know of no such command on
> > >>the
> > >> > >lower calcs, at least on the 83/83+ for sure.  And I'll go ahead and
> > >>tell
> > >> > >you,
> > >> > >since I don't know what calc you're looking to use, if its an 83/83+,
> > >> > >you're
> > >> > >screwed.  As far as anyone has been able to work it out, there is no
> > >> > >command
> > >> > >to convert a number to a string.  The only possible way (and a very bad
> > >>one
> > >> > >at
> > >> > >that) is to make a series of if/thens.  Unless you're desperate, I'd
> > >> > >suggest
> > >> > >figuring out a different way.
> > >> >
> > >> > NO! there is actually an easy way to do that on an 83!
> > >> >
> > >> > :"_"->Str1
> > >> > :Str1+sub("0123456789",A+1,1)->Str1
> > >> >
> > >> > A is the number that you want to input, and keep in mind that there has
> > >>to
> > >> > be a character in the first position of the string, or else it won't
> > >>work
> > >> > (It doesn't have to be a space like I put in).
> > >> >
> > >> > >Eric Tollefson
> > >> > >CmdrERT01@yahoo.com
> > >> > >
> > >> > >UT Rules wrote:
> > >> > >
> > >> > > > just store the number you were trying to store in quotation marks.
> > >>here
> > >> > > > goes:
> > >> > > >
> > >> > > > "1.2"->x
> > >> > > > Disp x
> > >> > > >
> > >> > > > or you can simply display the variable like this:
> > >> > > >
> > >> > > > 1.2->x
> > >> > > > Disp (or ouput which ever you use) "You entered"&string(x)&"."
> > >> > > >
> > >> > > > the syntax for the string() function is- string(variablename) if you
> > >> > >ever
> > >> > > > wanna use it again.
> > >> > > > hopefully you know about the ampersand(&) which lets you put
> > >>variables
> > >> > >in
> > >> > > > the sentences.
> > >> > > > if you need more help just e-mail me but i am sure one(both) of
> > >>those
> > >> > >will
> > >> > > > work.
> > >> > > >
> > >> > > > Ridge Racer
> > >> > > >
> > >> > > > >From: "Andrew Hivner" <ahivner@desupernet.net>
> > >> > > > >Reply-To: ti-basic@lists.ticalc.org
> > >> > > > >To: <ti-basic@lists.ticalc.org>
> > >> > > > >Subject: TIB: Real number to string
> > >> > > > >Date: Mon, 11 Sep 2000 22:50:49 -0400
> > >> > > > >
> > >> > > > >
> > >> > > > >how do you convert a real number to a string with the number in
> > >>it?,
> > >> > >ie:
> > >> > > > >1.2->x
> > >> > > > >magic part of program
> > >> > > > >Disp y
> > >> > > > >where y="1.2"
> > >> > > > >
> > >> > > > >Thanks
> > >> > > > >
> > >> > > > >Andrew
> > >> > > > >
> > >> >
> > >> >
> > >>_________________________________________________________________________
> > >> > Get Your Private, Free E-mail from MSN Hotmail at
> > >>http://www.hotmail.com.
> > >> >
> > >> > Share information about yourself, create your own public profile at
> > >> > http://profiles.msn.com.
> > >>
> > >>
> > >>_________________________________________________________
> > >>Do You Yahoo!?
> > >>Get your free @yahoo.com address at http://mail.yahoo.com
> > >>
> > >>
> > >
> > >_________________________________________________________________________
> > >Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> > >
> > >Share information about yourself, create your own public profile at
> > >http://profiles.msn.com.
> > >
> > >
> > >
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com



__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com



References: