Re: Letting integers be integers (when using //N)
- To: mathgroup at smc.vnet.net
- Subject: [mg27687] Re: Letting integers be integers (when using //N)
- From: drg at uiuc.edu (Daniel R. Grayson)
- Date: Sun, 11 Mar 2001 04:04:30 -0500 (EST)
- Organization: University of Illinois at Urbana-Champaign
- References: <98a14b$cl3@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"A. E. Siegman" <siegman at stanford.edu> writes: > 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 ? If you don't mind getting rational numbers out, try this: In[7]:= ?Rationalize Rationalize[x] takes Real numbers in x that are close to rationals, and converts them to exact Rational numbers. Rationalize[x, dx] performs the conversion whenever the error made is smaller in magnitude than dx. In[8]:= { 3, Sqrt[2], Pi } // N // Rationalize Out[8]= {3, 1.41421, 3.14159}