Re: Displaying Mixed Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg25144] Re: Displaying Mixed Numbers
- From: paulh at wolfram.com (P.J. Hinton)
- Date: Sun, 10 Sep 2000 21:25:39 -0400 (EDT)
- Organization: "Wolfram Research, Inc."
- References: <8pfdta$cuu@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <8pfdta$cuu at smc.vnet.net>, Jim Graber <jgraber at my-deja.com> writes: > While working with my third grader, I discovered the need > to make 5/3 display and print as 1 2/3 so she can check her > homework. > > I couldn't find a way to do this easily, so I wrote the following which > does the job. Is there an easier or better way? > Thanks. Jim Graber > > Mix1[x_] := { Quotient[Numerator[x], Denominator[x]], > Mod[Numerator[x], Denominator[x]]/Denominator[x]} > > Mix[x_] := Print[Mix1[x][[1]], Mix1[x][[2]]]; You may want to try adding a special formatting rule for Rational[] when the numerator is greater than the denominator. Unprotect[Rational]; Format[Rational[num_Integer, den_Integer], StandardForm] := DisplayForm[ RowBox[ { ToString[Quotient[num, den]], FractionBox[ToString[Mod[num, den]], ToString[den]] } ] ] /; num > den Protect[Rational]; -- P.J. Hinton User Interface Programmer paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.