MathGroup Archive 2000

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

Search the Archive

Re: Rounding Numbers in for output in GridBox


In a message dated 9/7/2000 11:06:02 PM, JOHN_C_ERB at prodigy.net writes:

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

genRound[x_, incr_:1] := incr*Round[x/incr];

nbrForm[x_, n_:2] := 
  NumberForm[x, {n + Ceiling[Log[10, x]], n}, NumberPadding -> {"", "0"}];

TableForm[Table[{
      x = 100*Random[], 
      genRound[x, 0.01] // nbrForm, 
      nbrForm[genRound[x, 0.25]], 
      nbrForm[genRound[x, 0.1], 1], 
      genRound[x], 
      genRound[x, 5]}, 
    {20}] , 
  TableAlignments -> Right, 
  TableHeadings -> {None, {"x", "{x, 0.01}", "{x, 0.25}", 
"{x, 0.1}", "{x, 1}", "{x, 5}"}}]


Bob Hanlon


  • Prev by Date: Re: writing mathematica script files for the math kernel under linux
  • Next by Date: Re: Manipulating Equations
  • Previous by thread: Rounding Numbers in for output in GridBox
  • Next by thread: Re: Rounding Numbers in for output in GridBox