[Tutor] Need more precise digits

Lloyd Kvam pythontutor@venix.com
Sat, 01 Dec 2001 16:00:20 -0500

```You really want something like:
avgsize = float(totalsize)/float(groups)

In older Python's:
22/10 = 2
float(22/10) = float(2) = 2.0

You need to convert to float BEFORE doing the division.

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)
>
> both totalsize and groups are integers
> I've got 10 groups
> sizes are:
> 2+3+2+2+3+2+2+2+2+2 = 22
>
> I should get 22/10 = 2.2.
>
> What I get is 2.0.  How do I get this missing 2 tenths?  As you can see
> from the above, I already casted to a float.
>
> Thanks,
> M
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:
603-443-6155
fax:
801-459-9582

```