Display Fractions as Mixed Numbers

860 views
Skip to first unread message

jonjoel

unread,
Jun 6, 2009, 5:01:13 PM6/6/09
to tinspire
Is it possible to have fractions greater than 1 display as mixed
numbers on the Calculcator page?

Thanks,

Jon Lepeska

TJ

unread,
Jun 6, 2009, 8:01:55 PM6/6/09
to tinspire
That is a very good question!
When I read it, I felt like there was a simple answer.
I guess I don't have a clear answer anymore.
I'm unsure...


As far as I know,
The calculator only spits out a faction.
I don't think it is programmed to spit out mixed number automatically,
but...
I think you can use something called "Proper Fraction".
(You can use it by the following: [menu] + [2:Number] + [7:Fraction
Tools] + [1:Proper Fraction].)
You can just press [menu] + 2 + 7 + 1 (for short).
That will give you the function "propFrac(". I know, it sounds
weird.
Put in your fraction, and then it will spit out the mixed number!
It will put a "+" sign between the number and the fraction, though. (I
really don't mind it, and I hope you also wont.)

So... For example... if you enter...

propFrac(9/5

... the calculator will spit out

1+ 4/5


I hope that answers your question.

Sincerely,
-TJ

Ross

unread,
Jun 6, 2009, 8:27:15 PM6/6/09
to tinspire
TJ, since I'm pretty sure that you are relatively new to this group, I
would just like to say welcome. Its nice to see more people willing
to help build and contribute to the TI-Nspire community. Anyways, the
solution that you gave isn't that complicated... It seems like you
thought that it was complicated, even though it was rather simple.
Also, you mentioned that there was an "unwanted" + in the middle of
the answer, so I decided to make a program that does this without the
+ sign. The code for it is below. Enjoy!

Define LibPub fraction(f)=
Prgm
n:=iPart(getNum(f))/(getDenom(f))
fr:=(getNum(f)-n)/getDenom(f)
Disp string(n)&" "&string(fr)
EndPrgm

Please note that in the last line of the program, the extra " " was
necessary to avoid having the number and the fraction being combined
into one fraction.

TJ

unread,
Jun 6, 2009, 8:55:44 PM6/6/09
to tinspire
but...
I'm not relatively new at all...

TJ

unread,
Jun 6, 2009, 8:58:16 PM6/6/09
to tinspire
... but Hi, anyways...

TJ

unread,
Jun 6, 2009, 9:00:33 PM6/6/09
to tinspire

Is half a year fairly recent?

TJ

unread,
Jun 6, 2009, 9:39:49 PM6/6/09
to tinspire
Dear Ross,

Well, I apologize for not having to formally introduce myself.
I am not relatively new to this group, but thank you for welcoming me,
otherwise.
Well, if I am relatively new, through opinion, I would almost be
certainly sure that you are relatively new too.

I've just done more private work than to the public, but in the end,
it never mattered.
After that, I was busy with my education... ...until now.
I thought I've encountered you before; I guess I am wrong.
Being wrong isn't always a bad thing because "uncertainty" holds the
universe together.

About your program...

" Define LibPub fraction(f)=
Prgm
n:=iPart(getNum(f))/(getDenom(f))
fr:=(getNum(f)-n)/getDenom(f)
Disp string(n)&" "&string(fr)
EndPrgm "

Well, I do appreciate your effort.
But I don't think it's worth doing this to remove for a simple "+"
sign.
01. Programs always display the word "done" after executing a
command.
I don't think anyone here can easily remove that.
02. The program isn't working for me, and I don't know why.
I'm sorry. I can't concentrate, and I'm also sick.
03 If this was a function, rather than a program...
It could easily integrate its outputs with other inputs.

For instance, the output of the program / function can be used as an
input of another.
That is seamless integration.


Sincerely,
-TJ

TJ

unread,
Jun 6, 2009, 10:03:32 PM6/6/09
to tinspire
04 Removing the "+" sign involves
adding the quotes.

I'd rather stay with the "+" sign.

05 I don't think it would be best to
eliminate the purpose of
having the built-in function
in the first place.

06 The propFrac function is easier to use.

Ross

unread,
Jun 6, 2009, 10:33:54 PM6/6/09
to tinspire
Sorry, I didn't realize that you had been here a while. It is just
that you have only recently been noticeably active, so I thought that
you were new. In addition, I noticed that you registered on
Lafacroft. About the program, I knew that it wouldn't be used, but I
did it to illustrate the point that you can most likely build a
program to do anything that the TI-Nspire doesn't have built in. I
would also just like to say that it would be nice if you would
consolidate all of your posts into a single post next time. Having 5
separate and short posts is unnecessary.

Eagle-Man

unread,
Jun 6, 2009, 10:41:39 PM6/6/09
to tins...@googlegroups.com
TJ,

For the sake of the people following this thread by email, could you
please take the time to combine your responses to a single thread into
one message? Over the last 2 hours I have received 13 messages from
you only pertaining to 5 threads, and most of them contain fewer than
10 words. Thanks.

Regarding your message, yes, programs display Done, and people can't
remove that...yet. Since the Nspire is relatively new, there hasn't
been much in the way of "hacking" being done, but don't fret. It's
being worked on (not by me, though). I know it's been discovered that
the tns files are really pkzip files containing a bunch of xml docs,
so it's only a matter of time.

And because of the way this works, even as a function you would not be
able to use the result as input to another calculation because it is a
string, not a number.

The original question, however, was only if you wanted it displayed as
a mixed fraction. There's no point to displaying it as a mixed
fraction if you're only going to use it in another calculation right
away. it's just a waste of computational time and button pressing.
So, if the point is to only view it as a mixed fraction, this should
work fine.

The point of Ross' program, and in fact many programs, isn't to
eliminate the built in one, but merely to provide a more desirable
input or output (in this case, esthetically speaking).

For example, I'm writing a string library (a port of Java's - I'll
post it here soon) and know that to get a substring, I could just use
the left(), right(), or mid() functions, but I find those confusing.
So, I have included two functions: substr(string, start, length) and
substring(string, start, end) which use left, right, and/or mid, but I
can access them in a much more intuitive way (to me).

--Eric

Nelson Sousa

unread,
Jun 7, 2009, 1:56:09 PM6/7/09
to tins...@googlegroups.com
How to display a string without the quotes:

Say you have a string stored in a variable, say str.
Instead of typing

Disp str

which will display the quotes, use this:

expr("Disp "&str).

The output won't have the quotes and can be copied and pasted into a
new calculation. But beware: as you're outputing 2+2/3 as 2 2/3, if
you paste it Nspire will understand it as a multiplication.

This technique was used in most programs on the linalg and linalgcas
libraries (which is where I learned about it).


cheers,
Nelson
Reply all
Reply to author
Forward
0 new messages