MathGroup Archive 2011

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

Search the Archive

Re: Rounding to a certain number of decimal places

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119284] Re: Rounding to a certain number of decimal places
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sat, 28 May 2011 07:21:28 -0400 (EDT)

You seem to be confusing two meanings of "round", or at least confusing 
rounding with specifying number of digits shown. For example,

   Round[0.99,10.^-3]
0.99

but

   NumberForm[0.99,{2,3}]
0.990



On 5/27/2011 6:14 AM, Andrew DeYoung wrote:
> Hi,
>
> I would like to be able to round a number to a certain, specified
> number of decimal places (not number of digits), including zeros.
> Suppose that some function f does this, and takes two arguments, the
> number to be rounded and the number of decimal places to which to
> round:  f[number, numPlaces].  Then, for example, I would like the
> following results, if possible:
>
> f[0.8168, 3] = 0.817
> f[1.8168, 3] = 1.817
> f[10.8168, 3] = 10.817
> f[100.8168, 3] = 100.817
> f[0.99, 3] = 0.990
> f[0.9, 3] = 0.900
> f[0.00572, 3] = 0.006
>
> Is there a function f (either built-in or a custom function) that can
> do this?  Mathmatica's built-in function NumberForm does not quite do
> this because the user specifies the number of digits, not the number
> of decimal places.  Also, NumberForm does not count zeros after the
> decimal point as digits, nor does it add extra zeros as needed if they
> are redundant.
>
> Am I getting into deep water here, or is there something
> straightforward that can do what I would like?
>
> I am running Mathmatica 7.  Also, I do not need to be able to do
> further computations on the output; I will be converting the output to
> a string, anyway.
>
> Thank you very much for your time.
>
> Andrew DeYoung
> Carnegie Mellon University
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Rounding to a certain number of decimal places
  • Next by Date: Re: Rounding to a certain number of decimal places
  • Previous by thread: Re: Rounding to a certain number of decimal places
  • Next by thread: Re: Rounding to a certain number of decimal places