Re: Displaying Mixed Numbers

• To: mathgroup at smc.vnet.net
• Subject: [mg25151] Re: [mg25124] Displaying Mixed Numbers
• From: BobHanlon at aol.com
• Date: Sun, 10 Sep 2000 21:25:44 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```In a message dated 9/10/2000 3:39:26 AM, 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]]];
>

SetAttributes[mix, Listable];

mix[r_Rational] := Module[{n = Numerator[r], d = Denominator[r], q, f},
q = Quotient[n, d];
f = Mod[n, d]/d;
If[q == 0, Print[f], Print[q, f]]];

mix[nr_] := Print[nr];

Then, all of the following are equivalent

mix[Table[n/4, {n, 0, 8}]];

Table[n/4, {n, 0, 8}] // mix;

Table[mix[n/4], {n, 0, 8}];

mix /@ Table[n/4, {n, 0, 8}];

mix[#] & /@ Table[n/4, {n, 0, 8}];

The last three forms would work even if mix had not been made Listable

Bob Hanlon

```

• Prev by Date: Re: Number Combining/Wheeling
• Next by Date: Re: NonlinearRegression
• Previous by thread: Displaying Mixed Numbers
• Next by thread: Re: Displaying Mixed Numbers