[Tutor] Need more precise digits

Steve Arnold sarnold@earthling.net
01 Dec 2001 16:23:13 -0800


On Sat, 2001-12-01 at 16:10, Danny Yoo wrote:
> On Sat, 1 Dec 2001, Mike Yuen wrote:
> 
> > I've trying to calculate an average and it looks like i'm losing some
> > precision in digits.
> > 
> > For example: i've got the following formula
> > avgsize = float(totalsize/groups)
> 
> The problem is one of timing: by the time float() works on its argument,
> we've already lost precision.  In Python,
> 
> ###
> >>> float(1/2)
> 0.0
> ###
[snip]

So either 1 or 2 needs to be a float; but what's with the 1 in the
following (python2 on redhat 7.2):

>>> float(1./2)
0.5
>>> float(1./3)
0.33333333333333331
>>> float(.1/3)
0.033333333333333333

Isn't the last one correct?

Steve