Re: How to display the desired numerical precision?

• To: mathgroup at smc.vnet.net
• Subject: [mg25241] Re: How to display the desired numerical precision?
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Sun, 17 Sep 2000 04:47:19 -0400 (EDT)
• References: <8psg4f\$a2m@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Christopher,

A number's precision and how it is displayed are independently controlable.
Display can be controlled using NumberForm  or PaddedForm.

Here is one way.

myForm[x_, n_:6] :=
NumberForm[SetPrecision[x, n],
ExponentStep -> Infinity
]

We need to turn off a message:

Off[NumberForm::"sigz"]

myForm[A[1234567.9, Pi, E, -1.2    ], 4]

A["1235000.", "3.142", "2.718", "-1.200"]

myForm[A[1234567.9, Pi, E, -1.2    ]]

A["1234570.", "3.14159", "2.71828", "-1.20000"]

Turn the message back on.

On[NumberForm::"sigz"]

If we leave  out the NumberForm we get numbers instead of strings but we
also get

SetPrecision[1234567.9, 4]

6
1.235 10

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Christopher R. Carlen" <crcarle at sandia.gov> wrote in message
news:8psg4f\$a2m at smc.vnet.net...
> Hi:
>
> In Mathematica 3, I could input
>
> N[ Pi, 12 ]
>
> and see 12 digits of result.  However in Mathematica 4 I see 6 digits, no
matter
> what I put in for the number of digits, unless >16.  In other words,
>
> N[ Pi, 17 ]
>
> shows 17 digits.
>
> It seems that for less than or equal to machine precision, the result
> gets displayed using the setting of Formatting Options|Expression
> Formatting|Display OPtions|Print Precision.
>
> But for numbers greater than the maching precision, the result displays
> according the precision specified to the N function.
>
> Can someone tell me how to get the following behavior from Mathematica 4:
>
> If I don't specify anything about precision, show 6 digits.
>
> Else if I specify any number of digits to N[] from 1 to n, then display
> n digits.
>
> Thanks for input.
> --
> _______________________
> Christopher R. Carlen
> Sr. Laser/Optical Tech.
> Sandia National Labs
>

```

• Prev by Date: RE: How to display the desired numerical precision?
• Next by Date: Re: Re: Random spherical troubles
• Previous by thread: RE: How to display the desired numerical precision?
• Next by thread: First derivative of interpolated spline