Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: round


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: RE: round
Date   Wed, 14 Sep 2011 11:54:15 +0100

I recommend otherwise.

Confusing (1) what decimal number you want stored, (2) how that is
held in binary and (3) what is to be displayed, which is really a
string, is a recipe for frustration.

To get a display to so many decimal places, use the appropriate
-format-. -round(whatever, .01)- just replaces one binary
approximation by another. Most multiples of .01 cannot be held
exactly.

-round()- is a very useful function for rounding to (multiples of)
integers. It is also defined, evidently, for non-integer second
arguments, but that does not mean it can deliver the impossible.

Over the years on Statalist, this question has I guess wildly appeared
hundreds of times. -search precision- for blog entries, articles and
FAQs on the subject, starting with anything written by Bill Gould.

Nick


On Wed, Sep 14, 2011 at 11:37 AM, Tim Evans <[email protected]> wrote:
> Would the following do the trick for you?
>
> gen real=round(obs, .01)
>
> Substitute real with the name of what you want to call your variable and replace obs with the name of the variable containing the .4378
>
> Tim
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Carla Horlacher
> Sent: 14 September 2011 11:24
> To: [email protected]
> Subject: st: round
>
> Hallo all!
>
> I have a quick question:
>
> how do I round numbers like .4378 to get only 2 digits after the point?
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index