RE: rounding off numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg23945] RE: [mg23884] rounding off numbers
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 16 Jun 2000 00:57:34 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message----- > From: JikaiRF at aol.com [mailto:JikaiRF at aol.com] To: mathgroup at smc.vnet.net > Dear members of MathGroup, > > I would like to report a problem rounding off numbers with > Mathematica. > > Take, for example, the number 81.3736. Since I want to round it > off to the > second decimal, I use the formula 81.3736 + (9-4)*0.001. And I obtain > 81.3786. > > Then, if I round off the third decimal point of the above result, > 81.3786, I > > can obtain the required answer 81.37. > > In order to establish the above procedure on Mathematica, I tried the > program: > > N[81.3736 +(9-4)*0.001, 4] > > However, the result was 81.38, because the function of N is, in this > situation, designed to > round > the third decimal of 81.3786, that is,8. > > I need to round off the third decimal in the above program. > I would like to know how to program Mathematica to achieve this. > > I hope to receive useful advice from you, as I have done previously. > > Sincerely, > Fujio Takata Fujio, The purpose of N is to convert exact numerical expressions into approximate expressions. In earlier versions it could be used to format output, but no longer. So it should not be used to format output, nor to set the precision or accuracy of a number, unless you are converting an exact number to an extended precision approximate number. If all you want to do is format the output, without actually changing the number use this: NumberForm[81.3736, {4, 2}] 81.37 On the other hand, if you wish to actually change the precision of the number you can use this: N[Round[100*81.3736]/100] 81.37 Or this: SetAccuracy[81.3736, 2] 81.37 See Section 3.1 in The Mathematica Book. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/