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: Why does "di round(85*0.7)" equal 59, rather not 60 ?


From   Grace Jessie <[email protected]>
To   <[email protected]>
Subject   RE: st: Why does "di round(85*0.7)" equal 59, rather not 60 ?
Date   Sun, 16 Jan 2011 13:15:57 +0000

 Maarten,
 Thank you very much!
 It helps a lot!
 
Grace


----------------------------------------
> Date: Sun, 16 Jan 2011 13:10:15 +0000
> From: [email protected]
> Subject: Re: st: Why does "di round(85*0.7)" equal 59, rather not 60 ?
> To: [email protected]
>
> --- On Sun, 16/1/11, Grace Jessie wrote:
> > Why does "di round(85*0.7)" equal 59 , rather not 60?
> > It is as following.
> >
> >
> > . di round(85*0.7)
> > 59
> > . di 85*0.7
> > 59.5
> > . di round(59.5)
> > 60
>
> That is a precision problem. You may think that 0.7 is a
> number which can be exactly represented with one number
> behind the decimal point, but that is only because we think
> in the decimal system. Computers, and thus also Stata, think
> in binary, and the number 7/10 in binary is like the number
> 1/3 in decimal.
>
> You can work around it by trying to work as much as possible
> with integers. Compare:
>
> di %20.15f (85*7)/10
>
> with
>
> di %20.15f 85*.7
>
> Hope this helps,
> Maarten
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>
>
> *
> * 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/ 		 	   		  
*
*   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