[Tutor] Need more precise digits
Lloyd Hugh Allen
Sat, 01 Dec 2001 16:03:04 -0500
It's enough to cast either of the arguments to division as a float (in
Python <= 2.1--haven't tried 2.2 yet, and can't remember whether integer
division was canned yet by then, or if that's 2.3).
avgsize = float(totalsize)/groups
will work (you don't have to float both)
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.
> Tutor maillist - Tutor@python.org