MathGroup Archive 2000

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

Search the Archive

Re: Rounding Numbers in for output in GridBox


John,

How about

newsufftable =GridBox[Map[PaddedForm[#, {4, 2}] &, newstuff1, {2}],
RowLines -> True,
    ColumnLines -> True, GridFrame -> True,
    ColumnSpacings -> 2] // DisplayForm
?

You might want to go a little further back in the construction and restrict
PaddedForm to the table entries, excudint the headings.

--
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

"JOHN C ERB" <JOHN_C_ERB at prodigy.net> wrote in message
news:8p9ktc$1ug at smc.vnet.net...
> I would like to make a nice table for printing.
> The table contains strings and numbers.
> I would like to have the numbers rounded (or formatted)
> to display to a specified number of digits or decimal points.
>
> The routine below is an attempt at rounding the numbers to two
> decimal places for output in table form using "GridBox."
>
> The problem is that the numbers are displayed to 15 decimal places,
> after they have been rounded.
>
> Any suggestions on displaying a specified number of digits or
> decimal points?
>
> I am using Mathematica 4.0.1 and Windows 98, 2nd Ed.
>
> My sample routine:
>
> (* generate a table *)
> stuff = Table[Random[Real, {0.1, 100}], {i, 3}, {j, 4}]
>
> (* add column titles *)
> columntitles = {"Numb 1", "Numb 2", "Numb 3", "Numb 4"};
> stuff1 = Prepend[stuff, columntitles]
>
> (* Display in a table form using GridBox *)
> stufftable =
>   GridBox[stuff1, RowLines -> True, ColumnLines -> True] // FrameBox //
>     DisplayForm
>
> (* Round the numbers to two deicmal places *)
> newstuff = Round[stuff*100]/100.0
> newstuff1 = Prepend[newstuff, columntitles]
>
> (* display the new table *)
> newstufftable =
>   GridBox[newstuff1, RowLines -> True, ColumnLines -> True] // FrameBox //
>     DisplayForm
>
>
> Thanks in advance
> John C. Erb
>
> email: John_C_Erb at prodigy.net
>




  • Prev by Date: Re: Rounding Numbers in for output in GridBox
  • Next by Date: Re: Security considerations in Mathematica&J/Link
  • Previous by thread: Re: Rounding Numbers in for output in GridBox
  • Next by thread: Re: Rounding Numbers in for output in GridBox