MathGroup Archive 1999

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

Search the Archive

RE: Help Formatting Outputs?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16977] RE: [mg16966] Help Formatting Outputs?
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sat, 10 Apr 1999 02:13:23 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Daly Gutierrez wrote,
----------------------------

I've been experimenting with formatting results to a desired number
of significant figures.  For the most part, I've found PrintPrecision
(in the "Option Inspector" window) quite useful.  However, I have a
couple of related questions...

1) How can I display Trailing Zeros?
ex: (253/11.2)*(1/0.62137)*(1/3.8754) = 9.60374 (displaying 6
significant
figures using PrintPrecision).  If I change this value to 3, the output
is 9.6 (when in fact I'd like to see 9.60).  I've even tried N[%, 3] but

still get 9.6 as a result.

2) Is there a way to display a result in scientific notation WITHOUT
using ScientificForm[expr]?  Perhaps using a similar feature in the
"Option Inspector" window? ex: (150/2.2046)*6 = 408.237 (again,
displaying 6 significant figures using PrintPrecision).  I would like to

get the same result as ScientificForm[%,1] or 4.x10^2 (in scientific
notation with 1 significant figure).  But it would be nice if I could do

it "in the background" so to speak (like changing the number of
significant figures using PrintPrecision).
------------------------------

I don't know of a way to do this that's completely transparent.  But you
PaddedForm can be a little helpful.  See the lines below.

In[1]:=
x1=PaddedForm[12.3,{4,3}]

Out[1]//PaddedForm=
" 12.300"


In[2]:=
{Head[%],Head[x1]}

Out[2]=
{Real,PaddedForm}

Now isn't that strange!  We don't get the same head for (x1) and (%).
If you don't like that you can change $OutputForms using the next line.


In[3]:=
Unprotect[$OutputForms];
$OutputForms=Complement[$OutputForms,{PaddedForm}];
Protect[$OutputForms];

In[4]:=
x2=PaddedForm[13.4,{4,3}]

Out[4]=
" 13.400"

In[5]:=
{Head[%],Head[x2]}

Out[5]=
{PaddedForm,PaddedForm}

Now (x1) and (%) have the same head, and you don't see (PaddedForm) in the
cell label.  If you want (x1) and (%) to have the head Real and formatted
with trailing zeros I can't help you.  Note that, for positive real numbers
PaddedForm leaves a space where you would get a minus sign for a negative
real number.  In spite of the fact that PaddedForm has several options I
can't find a way to prevent this space.

If you use the definitions below for $Post and $Pre PaddedForm will be used
automatically.  However, the darn white space before positive numbers
doesn't look good (see the example below).


In[6]:=
$Post=(#/.numb_Real:>
	PaddedForm[numb,{1+$PaddedRealDigits,$PaddedRealDigits}])&;
 
$PaddedRealDigits=3;

$Pre=(#/.PaddedForm[x_Real,_]:>x)&;


In[7]:=
expr=12.3 Sin[8.3 t+2]

Out[7]=
" 12.300" Sin[2+t " 8.300"]


In[8]:=
t=1/2;
expr

Out[8]=
"-1.633"

------------------------
I can't help you with your second question.
 
I agree it would be nice to have precise control over the way real numbers
are displayed without changing the head of the numbers.
 
 
Regards,
Ted Ersek


  • Prev by Date: shading in area
  • Next by Date: Re: Plot
  • Previous by thread: Re: Help Formatting Outputs?
  • Next by thread: Dynamic Programming