Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Number of digits

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73904] Re: Number of digits
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 3 Mar 2007 00:53:24 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <es90d7$2f4$1@smc.vnet.net>

Robert Pigeon wrote:
> 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
> 
> 
> 

Use NumberForm to control the display of numbers.

In[1]:=
NumberForm[x, {3, 2}, NumberPadding -> {"", "0"}] /.
   x -> 0.123456

Out[1]//NumberForm=
0.12

If you want this by default (rather that 6 decimal digits), you can set 
the $Post variable as in

In[2]:=
$Post = NumberForm[#1, {3, 2}, NumberPadding -> {"", "0"}] &

Out[2]//NumberForm=
Slot[1.00]&

In[3]:=
12.1234

Out[3]//NumberForm=
12.10

Regards,
Jean-Marc


  • Prev by Date: Cases to Select ?
  • Next by Date: Re: Integrals involving square roots
  • Previous by thread: Re: Number of digits
  • Next by thread: RE: Number of digits