Re: Rounding Numbers in for output in GridBox
- To: mathgroup at smc.vnet.net
- Subject: [mg25404] Re: [mg25086] Rounding Numbers in for output in GridBox
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 29 Sep 2000 01:06:46 -0400 (EDT)
- Organization: University of Western Australia
- References: <8pfehc$d3c@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <8pfehc$d3c at smc.vnet.net>, BobHanlon at aol.com wrote:
> 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
To produce formatted tables, I use the following code.
Cheers,
Paul
Notebook[{
Cell["To produce formatted tables, I use the following code:", "Text"],
Cell[BoxData[
\(TraditionalForm\`\(Needs["\<Utilities`FilterOptions`\>"];\)\)],
"Input",
InitializationCell->True],
Cell[BoxData[
\(TraditionalForm\`<< LinearAlgebra`MatrixManipulation`\)], "Input",
InitializationCell->True],
Cell[BoxData[
FormBox[
FormBox[\(PrettyTable[m_List, opts___] :=
DisplayForm[
StyleBox[
GridBox[m, Evaluate[FilterOptions[GridBox, opts]],
GridFrame -> 2, RowLines -> {1, 0}, ColumnLines -> {1,
0}],
Evaluate[FilterOptions[StyleBox, opts]],
Background -> GrayLevel[0.8]]]\),
"TraditionalForm"], TraditionalForm]], "Input",
InitializationCell->True],
Cell["To pad each column appropriately:", "Text"],
Cell[BoxData[
\(TraditionalForm\`\(SetOptions[PaddedForm, SignPadding -> True,
NumberSigns -> {"\<-\>", "\<\>"}];\)\)], "Input"],
Cell["For the (padded) data,", "Text"],
Cell[BoxData[
\(TraditionalForm\`nums :=
Table[{PaddedForm[x = Random[Real, {0, 100}], {6, 4}],
PaddedForm[x, {5, 3}], PaddedForm[x, {4, 2}],
PaddedForm[x, {2, 1}]}, {10}]\)], "Input"],
Cell["here is a formatted table:", "Text"],
Cell[BoxData[
FormBox[
RowBox[{"PrettyTable", "[",
RowBox[{
RowBox[{"BlockMatrix", "[",
RowBox[{"(", "\[NoBreak]", GridBox[{
{
RowBox[{"(", "\[NoBreak]", GridBox[{
{"\"\<r\>\"", "\"\<{r,0.001}\>\"",
"\"\<{r,0.01}\>\"", "\"\<{r,0.1}\>\""}
}], "\[NoBreak]", ")"}]},
{"nums"}
}], "\[NoBreak]", ")"}], "]"}],
",", \(GridBoxOptions -> {ColumnAlignments -> {Decimal}}\),
",", \(ColumnLines -> True\)}], "]"}], TraditionalForm]],
"Input"]
}
]
--
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia
Nedlands WA 6907
AUSTRALIA http://physics.uwa.edu.au/~paul