MathGroup Archive 2001

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

Search the Archive

Re: Letting integers be integers (when using //N)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27652] Re: [mg27628] Letting integers be integers (when using //N)
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Sat, 10 Mar 2001 00:49:42 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Isn't that what If is for?

In[1]:=
l={1,Pi,3/2,Sqrt[2]};


In[2]:=
N[l]

Out[2]=
{1., 3.14159, 1.5, 1.41421}

In[3]:=
If[IntegerQ[#],#,N[#]]&/@l

Out[3]=
{1, 3.14159, 1.5, 1.41421}


-- 
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/


on 3/9/01 8:35 AM, A. E. Siegman at siegman at stanford.edu wrote:

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



  • Prev by Date: Re: Question involving scope/recursion/arguments
  • Next by Date: Re: help create a unique solution system
  • Previous by thread: RE: Letting integers be integers (when using //N)
  • Next by thread: RE: Letting integers be integers (when using //N)