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

MathGroup Archive 1997

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

Search the Archive

Re: C f-format-like output in Mma

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7837] Re: [mg7710] C f-format-like output in Mma
  • From: David Withoff <withoff>
  • Date: Mon, 14 Jul 1997 03:01:17 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Andreas Siemer wrote:
> 
> Hi folks,
> 
> does anyone know whether there is a simple way to format output
> of real numbers in Mma with fixed space and a fixed number of digits
> following the decimal point in a way similar to the C or FORTRAN
> f-format?
> 
> Thanks for any suggestions!
> 
> --
> 
> ---------------------------------------------------------------------------
> From:    Dr. Andreas Siemer
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
>          Alfred-Wegener-Institut fuer Polar- und Meeresforschung
>          Sektion Physik I
>          Am Handelhafen 12
>          D-27570 Bremerhaven, Germany
> 
>          Tel.: +49-471-4831-524
>          FAX:  +49-471-4831-425   ( indicate recipient: Siemer/Physik I
> )
>          email: asiemer at AWI-Bremerhaven.de
> ---------------------------------------------------------------------------

Yes.

Here is one example.

In[8]:= data = Table[Random[] 10^k, {k, -20, 20, 5}]

                   -21            -16           -11            -6
Out[8]= {6.79773 10   , 4.93667 10   , 2.4602 10   , 1.74807 10  , 0.715808, 
 
                        9            14            18
>    58151.4, 1.34651 10 , 6.98729 10  , 3.97218 10  }

In[9]:= PaddedForm[ColumnForm[FortranForm /@ data], {8, 3}]

Out[9]//PaddedForm=      6.798e-21
                         4.937e-16
                         2.460e-11
                         1.748e-6
                         0.716
                     58151.398
                         1.347e9
                         6.987e14
                         3.972e18

There are many variants of this.  Using PaddedForm, NumberForm, etc., and
options of these functions you can basically do anything that you want.

Dave Withoff
Wolfram Research


  • Prev by Date: Re: Precision in own functions
  • Next by Date: Re: Breaking a sphere surface area into equal portions?
  • Previous by thread: Re: C f-format-like output in Mma
  • Next by thread: Re: Re: C f-format-like output in Mma