Re: Rounding Numbers in for output in GridBox

• To: mathgroup at smc.vnet.net
• Subject: [mg25101] Re: Rounding Numbers in for output in GridBox
• From: Albert Retey <albert.retey at visualanalysis.com>
• Date: Sun, 10 Sep 2000 03:14:26 -0400 (EDT)
• Organization: Visual Analysis
• References: <8p9ktc\$1ug@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```JOHN C ERB wrote:
>
> 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?
Hi John,

> 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

If I understand your problem right, you should have a look at
NumberForm, or at the following lines of code:

GridBox[Table[ {i, N[\[Pi], i], NumberForm[N[\[Pi], 20], {20, i}]}, {i,
1,
20}], RowLines -> True, ColumnLines -> True, GridFrame -> True,
ColumnAlignments -> {Center, Left, Right}] // DisplayForm

Hope that helps,

Albert Retey

--
Visual Analysis GmbH     Internet: www.visualanalysis.com
Neumarkter Str. 87       Telefon: 089 / 431 981 0
D-81673 Muenchen         Telefax: 089 / 431 981 1

```

• Prev by Date: Re: Add the Logarithms (error in integral)
• Next by Date: Re: Rounding Numbers in for output in GridBox
• Previous by thread: RE: Rounding Numbers in for output in GridBox
• Next by thread: Re: Rounding Numbers in for output in GridBox