Rounding numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg37002] Rounding numbers
- From: "Dana DeLouis" <delouis at bellsouth.net>
- Date: Sun, 6 Oct 2002 05:32:40 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello. Could somebody please inform me how to Round numbers to a certain Accuracy using Mathematica 4.2. This is not as easy as it sounds. Every function that I have read Rounds the Display, and not the actual number. For example, I am trying to round numbers to 5 digits to the right of the decimal place. The programming environment VBA has a "Round" function that does this (ROUND(1/7,5)), but Mathematica "Round" rounds to an Integer, so that is no good. Using "N" does not work for rounding a number, it only affects the display x = N[1./3 + 2./7, 5] 0.619048 I wanted 5, but it prints with "PrintPrecission" of 6. FullForm[x*5] FullForm[3.0952380952380953] As you can see, x was not rounded to 5 digits internally. It's even worse for exact numbers. Help talks about displaying Pi to 40 (I use 20 here). However, it does not mention the problem when it is less than 16. N[Pi, 20] 3.141592653589793238462643383255068`20 x = N[Pi, 4] 3.14159 (Note 6 digits and not 4 as asked) FullForm[x*2] FullForm[6.283185307179586] However, it does not matter, as x was not rounded anyway. An article mentioned using "NumberForm," but that only affects the display, and not the number. All the examples like NumberForm, ScientificForm, etc all affect the "Printing" of the number, not the number itself. Another option I thought of was a = SetAccuracy[1/3, 5] 0.3333333333333333333`4.5229 FullForm[a] FullForm[0.3333333333333333333`4.5229] All I want is a=0.33333 Thank you for any insight. -- Dana DeLouis Windows XP $VersionNumber -> 4.2 = = = = = = = = = = = = = = = = =