Re: Number of digits
- To: mathgroup at smc.vnet.net
- Subject: [mg73971] Re: Number of digits
- From: "Dana DeLouis" <dana.del at gmail.com>
- Date: Sat, 3 Mar 2007 23:52:13 -0500 (EST)
> ...I am making a table (using TableForm) of a list of answers to
> use in a report.
> I do not want to see 0.33333 in the table just 0.33!
Hi. Just an idea. Since a display to 2 decimal places is so common,
consider making your own function.
There are many variations, so this may give you some ideas.
My "nf2" is short for "NumberForm to 2 places."
SetAttributes[nf2, Listable]
nf2[n_] := NumberForm[n, {16, 2}, DigitBlock -> {3, Infinity},
NumberPadding -> {"", "0"}, ExponentFunction -> (Null & )]
SetOptions[TableForm, TableAlignments -> Right];
SeedRandom[2];
TableForm[nf2[Table[Random[]*100000, {r, 7}, {c, 4}]]]
--
HTH :>)
Dana DeLouis
Windows XP & Mathematica 5.2
& hopefully soon...6.0 ??
"Robert Pigeon" <robert.pigeon at videotron.ca> wrote in message
news:es90d7$2f4$1 at smc.vnet.net...
> Good afternoon,
> How can I force Mathematica to output an answer with a certain number of
> significant digits ? What I mean is I want the answer of, let say, 1.0 / 3
> to be output in Mathematica as 0.33 for example. The reason I want to do
> that is that I am making a table (using TableForm) of a list of answers to
> use in a report. I do not want to see 0.33333 in the table just 0.33 !
> I could use SetPrecision[1./3, 2], but I do not want to do that for every
> calculation. I have looked at $MachinePrecision and all other $.... , but
I
> cannot make sense out of it.
> So what I am trying to do, in a nut shell, is do what can be done with a
> pocket calculator, set my "visible" answer with a certain number of
digits!
>
> Thanks,
>
> Robert
>
> Robert Pigeon
> TZ = -5
>
>
>