MathGroup Archive 2003

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

Search the Archive

Re: Results with exactly two digits behind decimal point?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41683] Re: [mg41624] Results with exactly two digits behind decimal point?
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 30 May 2003 03:56:27 -0400 (EDT)
  • References: <200305291213.IAA03847@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I guess you can't have everything. First of all, bear in mind that 1000000/7
is a rational number, and the only way to make it look like a real number is
to use N or to insert a decimal point somewhere, such as 1000000/7. or
1000000./7. The result will have the internal precision kept by Mathematica,
but if you want to change the way it looks there is no way but to use
something like NumberForm. By default, Mathematica shows a fixed number of
digits in the display of any numerical calculation (e.g., 6), and the number
of decimals displayed may vary according to the size of the numbers
involved. Perhaps the only way out involves using a function for displaying,
but then you'll have to type your input twice, one for the actual
calculation and one more for displaying the result the way you want. For
example,

In[1]:=
r=1000000/7.

Out[1]=
142857.

This will keep track of your quotient with all the internal precision.
Define a function, just for displaying, such as

In[2]:=
p[x_]:=NumberForm[x,{12, 2}, NumberPadding->{"","0"},
ExponentFunction->(Null&)];

so that then

In[3]:=
p[r]
Out[3]//NumberForm=
142857.14

Using your notebook as a calculator implies that you will not be keeping
track of the results, so you wouldn't actually need to write twice. Simply
wrap p around any numerical calculation to display the result as desired:

In[4]:=
p[1000000./7]
Out[4]//NumberForm=
142857.14

You may add all sort of embellishments to the displaying function p, such
as, eg.,

In[5]:=
p[x_]:=NumberForm[x,{12, 2}, NumberPadding->{"" , "0"}, DigitBlock->3,
      ExponentFunction->(Null&)];

In[5]:=
p[1000000./7]
Out[21]//NumberForm=
142,857.14

Tomas Garza
Mexico City

----- Original Message ----- 
From: "Kai Velten" <khgbv at web.de>
To: mathgroup at smc.vnet.net
Subject: [mg41683] [mg41624] Results with exactly two digits behind decimal point?


> I have a notebook where I want to have all numerical results in the
> format
>
> xxxxxx.yy
>
> i.e. I want to have exactly two digits behind the decimal point.
>
> Ideally, I would like to write one or two initializing commands at the
> top of the notebook such that all following computational results are
> displayed in the above format. E.g., I would like to have "142857.14"
> as the result of "1000000/7", ideally without any need to issue any
> extra commands such as N[1000000/7] or similar. I.e., I would like to
> use Mathematica in this particular notebook like a pocket calculator
> (but, of course, whithout any loss of the internal precision of the
> calculations).
>
> Thank you for your help.
>
>



  • Prev by Date: Re: evaluation until failure
  • Next by Date: RE: Plot3D, how to plot only certain regions of a surface...
  • Previous by thread: Results with exactly two digits behind decimal point?
  • Next by thread: Plot3D, how to plot only certain regions of a surface...