RE: Letting integers be integers (when using //N)
- To: mathgroup at smc.vnet.net
- Subject: [mg27658] RE: [mg27628] Letting integers be integers (when using //N)
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
- Date: Sat, 10 Mar 2001 00:49:47 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
If this is only for Print, you may try:
In[51]:= a=5; b=Pi; c="what?";
In[54]:=
Attributes[preventIntegerfromN]={NHoldAll, Listable}
In[55]:= Format[preventIntegerfromN[i_Integer]]:=i
In[56]:= preventIntegerfromN[else_/;Head[else]=!=Integer]:=else
In[57]:=
Print[{{"a","b","c"},{a,b,c}//N@preventIntegerfromN[#]&}//TableForm]
>From In[57]:=
\!\(\*
TagBox[GridBox[{
{"\<\"a\"\>", "\<\"b\"\>", "\<\"c\"\>"},
{"5", "3.141592653589793`", "\<\"what?\"\>"}
},
RowSpacings->1,
ColumnSpacings->3,
RowAlignments->Baseline,
ColumnAlignments->{Left}],
Function[ BoxForm`e$,
TableForm[ BoxForm`e$]]]\)
No decimal point after 5 !
-- Hartmut
> -----Original Message-----
> From: A. E. Siegman [SMTP:siegman at stanford.edu]
To: mathgroup at smc.vnet.net
> Sent: Friday, March 09, 2001 8:36 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg27628] Letting integers be integers (when using //N)
>
> A convenient way to format and print the numerical values of a bunch of
> variables a,b,c, . . . neatly aligned directly under their corresponding
> names is
>
> Print[ { {"a", "b", "c", . . . .},
> {a, b, c, . . . . . } //N } //TableForm]
>
> The //N is needed for most of the variables in the list, because most of
> them will otherwise appear as messy expressions with lots of pi's and
> Sqrt[2]'s and such.
>
> The thing is, the variable a has an inherently integer value, and just
> being fussy I'd like it to print as an integer. But if I write the
> second list as
>
> {Round[a], b, c, . . . .}//N
>
> the a value still comes out with a decimal point. Any simple way to
> get rid of the decimal point on that one value, other than putting //N
> on each item of the list individually except for a ?