MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Displaying Mixed Numbers


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.


  • Prev by Date: Re: NonlinearRegression
  • Next by Date: Re: Faulty feature of Factor?
  • Previous by thread: Re: Displaying Mixed Numbers
  • Next by thread: RE: Displaying Mixed Numbers