Posts: 938
Threads: 104
Joined: Dec 2002
Is there a way to use like the TI-8x calculator function, FRAC (Which automatically puts the number into a fraction [if applicable]) AND, if so, how is this done? If someone knows a lengthy way to do it... and feel like explaining it, that's cool too!
Thanks.
-Nova
ovaProgramming.
One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.
Quote: Excellent. Now you can have things without paying for them.
BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
Posts: 273
Threads: 51
Joined: May 2002
Try this:
Function Fraction$(Number!)
Num1% = FIX(Number!)
Num2% = (1 / (Number! - Num1%))
Fraction$ = STR$(Num2% * Num1% + 1) + " /" + STR$(Num2%)
end function
Posts: 3,616
Threads: 287
Joined: Jan 2003
Nova! How are ya, haven't seen you around for a while.
Hmm...well, I don't believe there's any intrinsic function to express the fractional part in traditional fraction notation. In fact, there aren't any characters in the charset that allow any fraction.
But...
We can express fractions like this:
Code: PRINT "3"
PRINT "-"
PRINT "4"
Which, of course, gives the output:
3
-
4
Now, actually parsing numbers and converting them, that's another story. I can think of something like that to a very low precision:
Code: x=24
y=5
z=x/y
a$=STR$(z)
FOR i=1 to LEN(STR$)
IF MID$(a$,i,1)="." THEN 'we've reached the fractional part
b$=RIGHT$(a$,LEN(a$)-i,5)
END IF
NEXT
PRINT b$
PRINT "-"
PRINT "10"
Of course, that sucks, because it only handles one-decimal-place fractions. In fact, ignore that, beacuse it REALLY sucks.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 273
Threads: 51
Joined: May 2002
Zack: Look at my code above. It works.
Input: Fraction(1.111111)
Output: 10 \ 9
Input: Fraction(2.5)
Output: 5\2
Posts: 3,616
Threads: 287
Joined: Jan 2003
Oooh...posted before I saw it. Ah, well, ignore mine, I'm stupid.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 938
Threads: 104
Joined: Dec 2002
Thanks PI man! Err... R@dio...
lol, that's kind of weird, because the whole reason I asked is to write a program that converts Degrees to Radians and then uses a fraction in terms of PI. Trig class, ya know, and the teacher gives us extra credit for calculator programs; and I figure, if I can do it on QBasic then I could translate it into the Basic or whatever that's on my TI-86.
Zack:
I didn't know anyone cared
I am back now, for awhile! I guess I just got bored
ovaProgramming.
One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.
Quote: Excellent. Now you can have things without paying for them.
BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
Posts: 3,616
Threads: 287
Joined: Jan 2003
I remember ya. For some reason you stuck in my mind as the dude who made Monster Slayer...not sure why...is your name Noah Daleo?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 938
Threads: 104
Joined: Dec 2002
LoL, no...
I like to think of myself as the guy who is a newbie programmer who thinks that he's good.... Yeah... I know nothing
Okay, so I know this really should move to the "General" programming, but does anyone know how to do that on a TI-86 Graphing Calculator? I want to get both the top part of the fraction and the lower part of the fraction seperate, and then I could say easily
DISP A,"/",B
A being the top and B being the bottom, so I could put it somewhere other on the screen than JUST to the far right.
Thanks
ovaProgramming.
One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.
Quote: Excellent. Now you can have things without paying for them.
BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
Posts: 3,616
Threads: 287
Joined: Jan 2003
Hey, whaddya, know, we're exactly the same! How old are you? If we're the same age, I'll freak.
Re the calculator - isn't it just another BASIC dialect? So R@dioman's code should work...
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 729
Threads: 105
Joined: Feb 2003
It is. But here's a list of the stuff in R@dioman's code that would need to be changed cause it's not supported... please note that I'm refering to the TI 83+ here, and the TI 86 is prolly different o.O
- TI varibles are all A-Z, the Theta symbol, and some statistical others.
- TI varibles' values are set with the [STO] (store) key, which produces a symbol that looks like a little this: "->". Imagine that as one key.
- TI varibles are -all- precision vars, but can be rounded with round(, int(, and ipart( .
- TI programs can't use functions.
- There is no STR$ equivalent, while there is a function (called expr that converts strings in equation form into numbers. (expr("3") results in 3; expr("3+5") results in 8. It can use varibles too. go figure.)
- TI strings are all in the VARS menu, under 7: Strings, and are all Str# where # is a digit. (i.e; Str1, Str2...)
HOWEVER! The TI calcualator provides something much more useful to this cause! The Greatest Common Denominator! (aka, gcd( ) And fPart, which returns the everything to the right of the decimal point.
So... here's the long way Remember, everytime I use _> it's a store key, since there's no ASCII equivalent:
Code: :Input Z
:10^11_>S
:Z*S_>A
:fPart(Z)*S_>B
:gcd(A,S)_>G
:A/G_>A
:S/G_>B
:Disp A,B
The first number is the numerator, the second is the denominator.
*big wide grin*
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
|