Re: Letting integers be integers (when using //N)
- To: mathgroup at smc.vnet.net
- Subject: [mg27668] Re: Letting integers be integers (when using //N)
- From: Tom Burton <tburton at cts.com>
- Date: Sat, 10 Mar 2001 00:50:01 -0500 (EST)
- Organization: Brahea Consulting
- References: <98a14b$cl3@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello,
On 9 Mar 2001 02:35:39 -0500, in comp.soft-sys.math.mathematica you wrote:
> 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 ?
There must be several ways to do this. Here is one way. First, add to HoldForm the attribute "NHoldFirst" (or "NHoldAll") to keep N from getting inside HoldForm:
In[18]:=
Unprotect[HoldForm];
SetAttributes[HoldForm,NHoldFirst];
Protect[HoldForm];
Then do something like this:
In[21]:=
N[Replace[
{Sqrt[2], 1, Pi, 1.5},
i_Integer :> HoldForm[i],
{1}]
]
Out[21]=
{1.41421, 1, 3.14159, 1.5}
Expect more elegant ways from others;)
Tom