MathGroup Archive 2000

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

Search the Archive

RE: Rounding Numbers in for output in GridBox

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25128] RE: [mg25086] Rounding Numbers in for output in GridBox
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 10 Sep 2000 03:14:48 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

John,

Rounding by itself doesn't change the display characteristics of the
numbers. Want to format numbers? You have to use NumberForm for that. In
fact, you don't even have to use rounding. Use this:

(* Display the numbers to two decimal places *)
newstuff = Map[NumberForm[#, {4, 2}] &, stuff, {-1}];
newstuff1 = Prepend[newstuff, columntitles]

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> -----Original Message-----
> From: JOHN C ERB [mailto:JOHN_C_ERB at prodigy.net]
To: mathgroup 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: Security considerations in Mathematica&J/Link
  • Next by Date: Re: Add the Logarithms (error in integral)
  • Previous by thread: Re: Rounding Numbers in for output in GridBox
  • Next by thread: Re: Rounding Numbers in for output in GridBox